SED usage: sed ' Command ' filename (s) displays only results without modifying the file.
1, sed ' 2,5d ' file displays files, excluding 2-5 rows, but the number of rows exceeds the actual number of files in the file does not error.
The sed '/10[1-4]/d ' file displays file
have been looking at the Linux shell for a while to program, but also to complete some basic use, in order to deepen understanding, just see the Unix School a Sedawk tutorial, not a simple command parameter accumulation, but a fairly practical series, therefore, I hope to complete the translation in a few days. The translation process will not translate verbatim,
(redirect) to disk For instructions on how to use the SED command, including how to use the script file (not from the command line)Please refer to the second edition of Sed awk, author Dale Dougherty and Arnold Robbins(O ' reilly,1997;http://www.ora.com), "UNIX Text proces
| sed 'n'; s/\ N/\ t /'# Number of all rows in the file (the row number is left and the right of the text is aligned ).Sed = filename | sed 'n'; s/^ //; s/* \ (. \ {6, \} \) \ N/\ 1 /'# Number of all rows in the file, but only the row numbers of non-blank rows are displayed.Sed '/./= 'filename| sed'/./N; s/\ n //'# Ca
Like the awk mentioned above, sed is also a Unix text processing tool. Sed is short for StreamEditor. it can be filtered based on pattern matching (filtering is to find rows that meet certain conditions in the file) modify the text (that is, match the found... like the awk mentioned above, sed is also a
Like the awk mentioned above, sed is also a Unix text processing tool. Sed is the abbreviation of Stream Editor. It can be filtered based on pattern matching (the so-called filtering is to find rows that meet certain conditions in the file) modify the text (that is, modify the content that meets the conditions found ). 1. sed
Sed and awk are powerful text filtering tools in the UNIX environment.
With SED and awk, it is easy to edit local files, and it is easier to use regular expressions to filter out the output of other commands.
SED represents the stream Editor, which means that sed is a flow
Sed is one of the most important editors in Unix, note that there is one. Support a variety of editing tasks, this article will implement the functional example of the topic Suppose we have a text file called Empfile that contains the employee name and employee ID, as follows: Hilesh, 1001Bharti, 1002Aparna, 1003Harshal, 1004Keyur, 1005 1. How to add a header line to a file through
matching row
Sed '/hrwang/{n;s/my/your/;} ' datafile= Note: If you need to use more than one command, or if you need to embed an address within an address range, you must enclose the command in curly braces, write a single command per line, or separate multiple commands in the same row with semicolons.
One y
SED is simple to use, and we can provide SED commands directly on the command line or in the form of text files with SED commands. This tutorial explains the example of calling SED, which is available in both ways:Sed
'/^ $ /{N/^ $/D} 'FileThe function parameter N (refer to [section4.16]) adds the next row of blank rows to pattern space. Function parameter/^ $/D indicates that when a blank row is added, the first blank row is deleted, and the remaining blank rows are re-executed. Execute the command again and delete a blank row. The result is reversed until the blank row is added as a non-blank row. Therefore, only one blank row is output at the end of the consecu
with quotation marks and a file name.
Sed '/^ hrwang/\
> Hrwang and mjfan are husband \
> And wife 'datafile
# If the row starting with hrwang is found in the datafile file, add hrwang and mjfan are husband wife to the row.
6.8 I \ command
The I \ command inserts new text before the current line.
6.9 c \ command
did do feelthat I do D O'll miss you muchSearch Match display:Displays the line matching ' Miss ': sed- n '/miss/P' song.txt$ Sed-n '/miss/P'Miss you much10.- NParametersCancel Default OutputWhen the P command above is displayed, the-n parameter is used because the SED defaults to printing the input line on the screen
appended, each row must end with a backslash, except for the last line. The last line ends with a quotation mark and a file name.
sed‘/^hrwang/a\>hrwang and mjfan are husband\>and wife‘datafile#如果在datafile文件中发现匹配以hrwang开头的行,则在该行下面追加hrwang and mjfan are husband and wife
6.8 i\ CommandThe I\ command inserts a new text in front of the current line.6.9 c\ CommandSED uses this
existing text into new text.
6.10 n command
Sed uses this command to get the next line of the input file and read it into the mode buffer. Any sed command will be applied to the next line followed by the matching line.
sed
Sed is a non-interactive text editor that edits files or Copies files exported from standard input. The standard input may be from the keyboard, file redirection, string or variable, or a pipe file. Sed can edit small or large files at will. There are many sed commands used to edit and delete files and allow them to be absent from the site during this operation.
and read it into the mode buffer. Any sed command will be applied to the next line followed by the matching line.
sed‘/hrwang/{n;s/My/Your/;}‘datafile
Note: If you need to use multiple commands, or you need to nest an address within a certain address range, you must enclose the commands in curly brackets and write only one
Tags: title edit sed-n head BST make line body is bufferSedSed means the stream editor, which is commonly used as a filter in shell scripts and makefile, which introduces the output of the previous program to the input of SED, which is converted to another format output through a series of editing commands. Sed and vi both originate from the early
part of the match.\2Indicates the second part,\3Indicates the third part, which can be referenced in sequence. For example:
[qifuguang@winwill~]$ sed's/\(.*\)is\(.*\)line/\1\2/g'test.txt
this first
this second
this third
this fourth
this fifth
happy everyday
end
Regular ExpressionisThe two parts can be used.\1And\2Indicates that the function of this example is to delete the is in the middle.
Introduce shell variable in sed
end with a backslash, except for the last line. The last line ends with a quotation mark and a file name.Example:[Plain] view plaincopy
Sed '/^hrwang/a\
>hrwang and Mjfan are husband\
>and Wife ' DataFile
#如果在datafile文件中发现匹配以hrwang开头的行, append Hrwang and Mjfan are husband and wife below the line
8. I\ commandThe I\ command inserts a new text in front of the current line.9. c\ comm
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.