Sed ' s/pattern/replace_string/' file
Replace sed ' s/lifeng/lf/' sed.txt with LF for the first lifeng of each line in Sed.txt (the source file content will not change)
To replace all content, command tail plus parameter g sed ' s/lifeng/lf/g' Sed.txt
To match the second content of each line using 2g sed ' s/lifeng/lf/2g' Sed.txt
You can also use Cat Sed.txt | Sed ' s/lifeng/lf/' >file (output redirect)
If you want to directly modify the original file plus parameters –i sed –i ' s/lifeng/lf/' sed.txt
Sed–i. Bak ' s/lifeng/lf/' Sed.txt replaces the source file and creates a File.bak backup file
Sed removal of blank line sed '/^$/d ' sed.txt
blank line available regular ^$ to indicate /pattern/d The row that matches the style will be removed
Matched string token:& indicates matched content
[[email protected] csv]# echo this was an example|sed ' s/\w\+/[&]/g '
[This] [IS] [An] [Example]
[[email protected] csv]# echo this was an example|sed ' s/\w\+/[&]/'
[This] was an example
Regular \w\+ matches each word and then we replace it with [&] & corresponds to the word that was previously matched
Quotes
Sed expressions are generally quoted in single quotes, but they can also be used in double quotes, and double quotation marks can be extended by evaluating an expression, and double quotes are useful when we want to use some variables in an SED expression.
Example: Text=hello
echo Hello word|sed "s/$text/hello/" (single quote not)
HELLO Word
This is to delete the first row to the nth row
Sed-i ' 1,nd ' filename
sed commands use simple records