Sed is useful for a lot of different things.
Sub or remove names in a list of files
In this example we have a number of files all starting with text that we want to remove.
Ex.
000-importantDocs1.csv
000-importantDocs2.csv
000-importantDocs3.csv
000-importantDocs4.csv
for i in *.csv
do
mv "$i" "`echo $i | sed 's/000-//'`"
done
Remove N lines from Beginning or End of File
#Remove first 1000 lines from file
sed '1,1000d' program.log > program.new.log
#Remove all lines from 3800 to End from file
sed '3800,$d' program.log > program.new.log
Replace Text within File
sed -i 's/foo/bar/g' file.txt
Replace Entire line within File
The Example below would match the line starting with server in the file /etc/ipa/default.conf.
sed -i "/^server/c\server = ipa1.prod.infra.us-east-1.aws.example.com" /etc/ipa/default.conf
The resulting line would be server = ipa1.prod.infra.us-east-1.aws.example.com