Introduction to sed commands in AIX [plain] www.2cto. comsed: a non-interactive text stream editor that can edit large or small files. The sed command regularly edits and deletes files and processes all changes at a time. Sed does not deal with the original file, but only operates a copy of the source file. however...
Introduction to sed commands in AIX [plain] www.2cto.com sed: it is a non-interactive text stream editor that can edit large or small files, and regularly edit and delete files with sed commands. all changes are handled at one time. Sed does not deal with the original file, but only operates a copy of the source file, and all the changes are output to a file and output to the screen. Three methods to call sed: 1. type the command through the command line 2. Insert the sed command into the script file, and then call sed 3. Insert the sed command into the script file and make the sed script executable? Automatic execution? Call sed 1. command format: sed [option] sed command input file 2. use sed script sed [option]-f sed script file input file 3. use the sed script file sed script with sed command interpreter in the first line [options] input file options: n do not print c the next command is the edit command [useless] f is calling the sed script file save sed command, you can use the redirection method: when sed 'SED _ cmd' input_file> outfile sed is used to browse files, the first line is used by default. to locate the text, you can use either of the following methods: 1. use line number, single line or multiple rows (range) 2. the regular expression uses sed to locate the text in the file ---------------------------------------------------------------- x indicates the row number. for example, 1 x indicates that the row number ranges from x to y/pattern/to query rows. For example,/disk/or/[a-z] // pattern/queries rows that contain two modes, such as/disk/disks/pattern /, x queries rows in the include mode on the given row number, for example,/ribbon/, 3 x,/pattern/queries matching rows through the row number and mode, 3,/vdu/x, y! Query rows that do not contain the specified row numbers x and y! Export sed Edit command ------------------------------------------------------ p print match line = display file line number a \ add new text information after locate line number I \ insert new text information after locate line number d delete locate line c \ new text replacement positioning text s use replacement mode to replace the corresponding mode r reads text from another text w write text to a file q after the first mode matching is completed or immediately releases l display and the equivalent control character {} of the ASCII code reads the next line from another text in command group n executed on the positioning line, append mode 2 to/pattern n/y in the next line g to continue to the next input line; allow cross-line mode matching statement -------------------------------------------------------- create a file: vi quote.txt pg quote.txt the honeysuckle band played all night long for noly $90. it was an evening of splendid music and company. too bad the disco floor fell through at 23:10. the local nurse Miss P. neave was in attendance. print The first line: sed-n '1p' quote.txt The honeysuckle band played all night long for noly $90. print The last line: sed-n' $ P' quote.txt The local nurse Miss p. neave was in attendance. print The entire file in The format of 1, $ p sed-n '1, $ P' quote.txt The honeysuckle band played all night long for noly $90. it was an evening of splendid music and company. too bad the disco floor fell through at 23:10. the local nurse Miss P. neave was in attendance. print The specified row sed-n '4p' quote.txt The local nurse Miss P. neave was in attendance. use a regular expression to print rows containing was words; sed-n'/was/'p quote.txt [or sed-n'/was/p' quote.txt] It was an evening of splendid music and company. the local nurse Miss P. neave was in attendance. search data: print the row sed-n'/with the word ending with ing '/. * ing/'p quote.txt It was an evening of splendid music and company. find The row containing The $ symbol: sed-n'/\ $/'p quote.txt The honeysuckle band played all night long for noly $90. filter out a row in The format of line_num,/pattern/sed-n'4,/was/'p quote.txt The local nurse Miss p. neave was in attendance. print The row number: sed-E' = 'quote.txt 1 The honeysuckle band played all night long for noly $90. 2 It was an evening of splendid music and company. 3 Too bad the disco floor fell through at 23:10. 4 The local nurse Miss P. neave was in attendance. print the row number that contains the was word: sed-n'/was/= 'quote.txt 2 4 the row that contains the was: sed-n'/was/'p quote.txt It was an evening of splendid music and company. the local nurse Miss P. neave was in attendance. print the row number and row data that contain music: sed-e '/music/='-n-e'/music/p' quote.txt 2 It was an evening of splendid music and company. -- the end --
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