System sed usage in AIX

Source: Internet
Author: User
Tags db2 insert
System sed in AIX uses sed to modify or delete characters or strings in text. When 1. find the row containing & quot ;#& quot;: The system sed in awk... AIX uses sed to modify or delete characters or strings in the text. Www.2cto.com pg func.txt 0at $ the @ begining ^ M The # file # name # is # func, ^ M 9and % it's % suffix % is. txt 1. find the row that contains "#": awk '$0 ~ // #/'Func.txt The # file # name # is # func, ^ M 2. replace The first line containing "#" with a space: sed-n's/# // P' func.txt The file # name # is # func, ^ M 3. replace all "#": sed's/# // g' func.txt 0at $ the @ ining ^ M The file name is func, ^ M 9and % it's % suffix % is. txt 4. replace the number starting with The row: sed's/^ [0-9] * // g' func.txt at $ the @ ining ^ M The # file # name # is # func, ^ M and % it's % suffix % is. txt 5. remove ^ M from the end: sed's/^ M $ // g' func.txt 0at $ The @ begining ^ M the # file # name # is # f Unc, ^ M 9and % it's % suffix % is. txt why not replace it? Originally ^ is a special character. escape sed's/\ ^ M $/g 'func.txt 0at $ the @ ining The # file # name # is # func, 9and % it's % suffix % is. txt www.2cto.com 6. the following commands are all integrated: pg func.txt 0at $ The @ begining ^ M the # file # name # is # func, ^ M 9and % it's % suffix % is. txt at func.txt | sed's/\ $ // g' | sed's/@ // g' | se's/^ [0-9] // g' | sed's/\ ^ M $/g' | sed's/# // g' | sed's/% // g' at the begining The file name is func, and it's suffix is. txt can also use these commands Put it in the file: pg func. sed #! /Bin/sed-f # drop the "#" s/# // g # drop the number at the first of each line s/^ [0-9] // g # drop the "$" s/\ $/g # drop the "@" s/@/g # drop the "%" s/% // g # drop" ^ M "s/\ ^ M/g # EOF: sed-f func. sed func.txt at the begining The file name is func, and it's suffix is. txt saves the filtered results to sed. in the out File: sed-f func. sed func.txt> sed. out pg sed. out at the begining The file name is func, and it' S suffix is. txt below is an applicable example where the data I searched for from the database is placed in a file: pg SQL .txt LASTNAME SALARY ------------- ----------- HAAS 152750.00 THOMPSON 2 Records selected. The current requirement is to retrieve the LASTNAME, which can be as follows: cat SQL .txt | sed '/^ -- */d' | sed'/^ $/d' | sed '$ d' | sed '1D' | awk '{print $1} 'Retrieve the number: cat SQL .txt | sed '1D '| sed' $ d' | sed '/^ $/d' | sed'/^ -- */d' | awk '{print $2} '2014 152750.00 94250.00 append information to each row pg info.txt yeeXun Linux Aix Unix Windows www.2cto.com sed's/[a-zA-Z] */&-end-/g' info.txt yeeXun-end -Linux-end-Aix-end-Unix-end-Windows-end-pass the value to sed in the command line, double quotation marks: NAME = "Scott in Oracle" REPLACE = "OUT" echo $ NAME | sed "s/in/$ REPLACE/g" Scott OUT Oracle contains some line commands ([] indicates space, [] indicates the tab key) -------------------------------------------------------------------'s /\. $ // g' delete. the ending line '-e/abcd/d' deletes the row containing abcd' s/[] [] [] */[]/g' and replaces multiple spaces with one space' s/^ [] [] * // g' delete the first space of a row's /\. [] [] */[]/g' with a space. remove multiple spaces '/^ $/D' to delete empty rows' s/^. // g' delete the first character's/COL \(... \) // g' delete the first \'s /[]/[]/ 'use spaces to replace the tab key's/^ [] // g' to delete all the first tab keys in the row's/[] * // g' to delete all the tab keys. sort script Set 1. delete The First \: echo $ PWD | sed's/^ \ // g' usr/xxxx/ytcclb/sed 2. additional text: echo "Mac Wong" | sed's/Mac/& J. /g'mac J. wong 3. get the file name and remove the suffix: view the files in the current directory: ls-l total 20-rwxr -- r -- 1 b4nx group 78 Dec 4 append. sed-rw-r -- 1 b4nx group 48 Dec 4 10:01 change. sed-rw-r -- 1 b4nx group 181 Dec 6 10:41 func. sed-rw-r -- 1 b4nx group 69 Dec 6 09:58 func.txt-rw-r -- 1 b4nx group 30 Dec 8 13:57 info.txt-rw-r -- 1 b4nx group 44 Dec 4 09:56 insert. sed-rw-r -- 1 b4nx group 201 Nov 27 quote.txt-rw-r -- 1 b4nx group 63 Dec 6 sed. out-rw-r -- 1 b4nx group 5 Dec 4 sedex.txt-rw-r -- 1 b4nx group 125 Dec 6 SQL .txt get the file name: ls-l | awk '{print $9}' | sed '/^ $/d' | sed's /\.... // g'append change func info insert quote sed sedex SQL 4. add a suffix to the file 3. db2: ls-l | awk '{print $9}' | sed '/^ $/d' | sed's /\.. * $ // g' | sed's/$ /. db2/g'append. db2 change. db2 func. db2 func. db2 info. db2 insert. db2 quote. db2 sed. db2 sedex. db2 SQL. db2 note: get the file suffix sed's /\.. * $ // g'5. replace multiple characters (including spaces ): str = "Guiyang & is thecapital of GuiZhou" echo $ str | sed's/& // g' | sed's/the/g' Guiyang is the capital of GuiZhou -- the end --
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.