https://www.cnblogs.com/ev-zhk/p/4277023.html
sed -i command Detailed
[root @ www ~] # sed [-nefr] [ action] options and parameters: -n: Use quiet (silent) mode. Sed in general usage, all data from STDIN generally will be listed to the terminal. However, if after adding -n parameter, only through the line sed special treatment (or action) will be listed. -e: directly on the command-line mode of action sed editor; -f: sed directly to the action in a written document, -f filename you can run sed action in the filename; -r: sed action is supported regular expression syntax of the extension type. (The default is the basis of regular expression French and France) -i: directly modify the contents of the file to read instead of output to the terminal. Action Description: [N1 [, n2]] function N1, n2: not necessarily exist, usually on behalf of "the number of rows selected for action", for example, if my action is needed between 10-20 rows , the "10, 20 [action behavior]" function: a: new, can take back a string, and those strings come in a new line (currently the next line) ~ c: to replace, c behind can take a string, these strings can be substituted n1, N2 between the line! d: Delete, because it is deleted ah, so the back are not normally connected to any pound d; i: insert, i can take back the string, which string appears (the line current) is a new line; P: Print, that will print a selection of data. P will usually run together with the parameters sed -n ~ s: replace, the work can be substituted directly miles! Usually this s action can be used with regular expression! For example 1,20s / old / new / g is it!
sed -i is a text file directly operate
sed -i 's / original string / new string /' /home/1.txt sed -i 's / original string / new string / g' /home/1.txt
The difference between these two commands is to see an example of it
This is the content of 1.txt
#cat 1.txt d ddd #ff
Look at the difference between these two commands execute it
sed -i 's / d / 7523 /' /home/1.txt execution result 7523 7523dd #FF Sed -i 'S / D / 7523 / G' /home/1.txt execution result 7523 752 375 237 523 #FF
Remove the "first line" with "@" @ initials
sed -i 's/^@//' file
Insert a new line character string preceding the particular
sed -i '/ specific string / i newline character string' file
After a particular row insert a new line character string
sed -i '/ specific string / a newline character string' file
To delete a specific string
sed -i '/ string / d' file
sed -i "s\\"""\\\\g" tmp
[root @ www ~] # sed [-nefr] [ action] options and parameters: -n: Use quiet (silent) mode. Sed in general usage, all data from STDIN generally will be listed to the terminal. However, if after adding -n parameter, only through the line sed special treatment (or action) will be listed. -e: directly on the command-line mode of action sed editor; -f: sed directly to the action in a written document, -f filename you can run sed action in the filename; -r: sed action is supported regular expression syntax of the extension type. (The default is the basis of regular expression French and France) -i: directly modify the contents of the file to read instead of output to the terminal. Action Description: [N1 [, n2]] function N1, n2: not necessarily exist, usually on behalf of "the number of rows selected for action", for example, if my action is needed between 10-20 rows , the "10, 20 [action behavior]" function: a: new, can take back a string, and those strings come in a new line (currently the next line) ~ c: to replace, c behind can take a string, these strings can be substituted n1, N2 between the line! d: Delete, because it is deleted ah, so the back are not normally connected to any pound d; i: insert, i can take back the string, which string appears (the line current) is a new line; P: Print, that will print a selection of data. P will usually run together with the parameters sed -n ~ S: replace, the work can be directly substituted miles! Usually this s action can be used with regular expression! For example 1,20s / old / new / g is it!
sed -i is a text file directly operate
sed -i 's / original string / new string /' /home/1.txt sed -i 's / original string / new string / g' /home/1.txt
The difference between these two commands is to see an example of it
This is the content of 1.txt
#cat 1.txt d ddd #ff
Look at the difference between these two commands execute it
sed -i 's / d / 7523 /' /home/1.txt execution result 7523 7523dd #FF Sed -i 'S / D / 7523 / G' /home/1.txt execution result 7523 752 375 237 523 #FF
Remove the "first line" with "@" @ initials
sed -i 's/^@//' file
Insert a new line character string preceding the particular
sed -i '/ specific string / i newline character string' file
After a particular row insert a new line character string
sed -i '/ specific string / a newline character string' file
To delete a specific string
sed -i '/ string / d' file
sed -i "s\\"""\\\\g" tmp