Sed is a non-interactive text editor.
It edits files or standard input export text copy instance 1. row matching root @ mypc/] # sed-n ' 2p '/etc/passwd prints out 2 root @ mypc/] # sed-n ' 1, 3p '/etc/passwd prints 1 to 3 lines of root @ mypc/] # sed-n ' $ p '/etc/passwd print out the last line root @ mypc/] # sed-n '/user/' p/etc/passwd to print out a row containing user rpc: x: 32: 32 PortmapperRPCuser:/:/sbin/nologinrpcuser: x:29: 29 RPCServiceUser:/var/lib/nfs:/sbin/nologinroot @ mypc/] # sed-n '/\ $/' p/etc/passwd to print out a row with $ metacharacter, $ means last row 2. insert text and additional text (insert a new row) root @ mypc/] # sed-n '/FTP/p '/etc/passwd print out a row with FTP ftp: x: 14: 50: FTPUser:/var/ftp:/sbin/nologinroot @ mypc/] # sed '/FTP/a\456 '/etc/passwd rows containing FTP behind newly inserted row, 456root @ mypc/] # sed '/FTP/i\123 '/etc/passwd in front of rows containing FTP new insert row, 123root @ mypc/] # sed '/FTP/i\ "123" '/etc/passwd in front of rows containing FTP new insert row content is "123" root @ mypc/] # sed ' 123 ' 5a\/etc/passwd in line 5, insert a new row, 123root @ mypc/] # sed ' 5i\ "12345" '/etc/passwd 5 before inserting a new row, "12345" 3. delete text root @ mypc/] # sed ' 1d '/etc/passwd delete row 1 root @ mypc/] # sed ' 1, 3d '/etc/passwd delete rows 1 to 3 root @ mypc/] # sed '/user/d '/etc/passwd delete rows with user 4. replacing text, replace command with replace mode to replace the specified pattern in the format: [address [, address]] s/pattern-to-find/replacement-pattern/[gpwn] root @ mypc/] # sed "s/user/USER/'/etc/passwd will substitute the first user to USER, g show alternate root @ mypc/] # sed" s/user/USER/g '/etc/passwd will replace all user USERroot @ mypc/] # sed "s/user/# user/'/etc/passwd will substitute the first user to user, such as for # shielding effect root @ mypc/] # sed" s/user//'/etc/passwd will be the first user with an empty root @ mypc/] # sed "s/user/& 11111111111111/'/etc/passwd if you want to add or modify a long string, you can use (&) command, & save discovery mode to recall it, and then put it in the replacement string, here is the front & drop root @ mypc/] # sed" s/user/11111111111111 &/'/etc/passwd here is placed behind the & 5. rapid line below is some line command set. ([] [] Represents a space that represents the tab-key) ' s/\. $//g ' delete row ' end with a period-e/abcd/d ' delete rows containing the abcd ' s/[] [] [] */[]/g ' delete one or more spaces, use a space instead of the ' s/^ [] [] * remove row first//g ' spaces ' s/\. [] [] */[]/G ' delete a period followed by two or more spaces and replace them with a space ' '/^ $/d ' Delete blank lines ' s/^.//g ' remove first character ' s/COL\ (...\)//g ' remove COL ' immediately after the three-letter ' s/^////g ' removed from the path first \ ' s/[]/[]//g ' remove all spaces and tab keys instead of the ' S/^ []//g ' delete rows first all tab ' s/[] *//g ' Removes all the tab key if you use the sed, the file filter is a good idea to make the problem into a few steps, step through, and edge implementation side of the test results.
No comments:
Post a Comment