The sed command is a stream editor used for filtering and transforming text.
sed 'command' file
Create and view the initial content of sample.txt:
echo -e "Hello World\nThis is a sample file\nBash scripting is powerful\nLearning grep, awk, and sed\nAnother line with the word World" > sample.txt
cat sample.txt
Output:
Hello World
This is a sample file
Bash scripting is powerful
Learning grep, awk, and sed
Another line with the word World
Substitute a string in the file:
sed 's/World/Universe/g' sample.txt
Hello Universe
This is a sample file
Bash scripting is powerful
Learning grep, awk, and sed
Another line with the word Universe
Edit files in place:
sed -i '' 's/sample/example/g' sample.txt
Delete lines containing the word "Bash":
sed '/Bash/d' sample.txt
Hello World
This is a example file
Learning grep, awk, and sed
Another line with the word World
标签:sample,sed,command,file,World,txt,Bash
From: https://www.cnblogs.com/Answer1215/p/18197684