System sed in AIX uses sed to modify or delete characters or strings in 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 B 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 --