Linux sed command detailed

Source: Internet
Author: User

Linux Environment: Ubuntu16.04

SED command

Http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html

http://blog.csdn.net/yiqingnian28/article/details/23133043

Regular expressions

http://blog.csdn.net/wzzfeitian/article/details/8842371

Sed-help viewing the use of SED

-N,--quiet,--silent suppress automatic printing of pattern space   prevents the default output (display) of data in the template space, at which point only the content specified by the p command is output. 
-E script,--expression=script Add the script to the commands to be executed will specify the scripts The commands in script are added to the command group that processes the input file
-F script-file,--file=script-file Add the contents of script -file to the commands to be executed
Adds the command in the specified script script-file to the command group that processes the input file.
--follow- in
Only works in systems that support symbolic connections, and with option-I at the same time: if the specified input file is a symbolic connection, SED processes the target file for the symbolic connection and maintains the connection. The default SED disconnects so that the destination file for the symbolic connection is not modified.

-i[suffix],--in-place[=inif
Place the file in the In-place edit processing. GNU is implemented by creating a temporary file and sending the output of the SED to this file instead of sending it to standard output. Applies to the command: =, a, c, I, L, p, but also the command W or W and the output file is specified as/dev/stdout, the output of SED is also sent to the standard output.
This option has implied another option-S. There can be no space between I and suffix
When a file finishes processing, the SED creates a temporary file name that is replaced with the original name of the output file (that is, the input filename being processed). If a suffix suffix is specified, the old file is replaced with a suffix suffix and the old file is overwritten without a backup.
The rule of change is: If suffix does not contain an asterisk (*), append suffix as a suffix directly after the old file name, otherwise, each asterisk (*) in suffix is replaced by the old file name. The advantage is that you can also specify a prefix for the backup file, not just the suffix, or even put the backup in another directory (the directory must already exist)
-L-N,--line-length=N Specify the desired line-wrap length forThe ' L'Command--POSIX disable all GNU extensions.
Specifying the L (L) command wrap length to n,0 means that the long line is not wrapped in a line, and the default is 70.

-R,--regexp-extended Use extended regular ExpressionsinchThe script.
An extended regular expression rule is used to interpret the matching template.

-S,--Separate consider files as separate rather than as a single continuous long stream.
The default SED considers multiple input files specified on the command line as a continuous, long stream of data. With this GNU extension option, SED will be treated as individual files,
Note, however, that the specified range of addresses cannot span other files, that the displayed line numbers are relative to the first line of the respective file, that the character $ indicates the last line of each file, and that the calling file from the R command is re-executed once for each input file.

-U,--unbuffered load minimal amounts of data fromThe input files andflush the output buffers more often
Both the input and output are based on the actual, as small as possible buffer processing, or do not buffer. The input to the SED command comes from something like command tail–f, and you want to see the processed output as quickly as possible, which is especially useful.

-Z,--null-data separate lines by NUL characters
--help Display this Help andexit
Exits when the SED parameter information is displayed.
 and exit
Exits after displaying SED version information.

Intercept data from line fifth:

' 5p '

Replace multiple spaces with a single space:

[Email Protected]:/home/jianeng#How is   you! fine! Thank   
[Email protected]:/home/jianeng# sed ' s/\ */\/g ' test.txt

Delete the data behind the man:

[Email Protected]:/home/jianeng#head/etc/passwdroot:x:0:0:root:/root:/bin/bashdaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologinbin:x:2:2:bin:/bin:/usr/sbin/nologinsys:x:3:3:sys:/dev:/usr/sbin/nologinsync:x:4:65534:sync:/bin:/bin/syncgames:x:5:60:games:/usr/games:/usr/sbin/nologinman:x:6:12:man:/var/cache/man:/usr/sbin/nologinlp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologinmail:x:8:8:mail:/var/mail:/usr/sbin/nologinnews:x:9:9:news:/var/spool/news:/usr/sbin/Nologin
[Email protected]:/home/jianeng#head/etc/passwd | grep ' man: ' | sed ' s/:.*//g 'Mans

Linux sed command detailed

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.