2013-08-24 01:00:37 +02:00
|
|
|
# To replace all occurrences of "day" with "night" and write to stdout:
|
2013-08-21 06:17:52 +02:00
|
|
|
sed 's/day/night/g' file.txt
|
2013-08-11 21:37:11 +02:00
|
|
|
|
2013-08-24 01:00:37 +02:00
|
|
|
# To replace all occurrences of "day" with "night" within file.txt:
|
2013-08-21 06:17:52 +02:00
|
|
|
sed -i 's/day/night/g' file.txt
|
2013-08-11 21:37:11 +02:00
|
|
|
|
2013-08-24 01:00:37 +02:00
|
|
|
# To replace all occurrences of "day" with "night" on stdin:
|
2013-08-21 06:17:52 +02:00
|
|
|
echo 'It is daytime' | sed 's/day/night/g'
|
2013-08-26 23:06:30 +02:00
|
|
|
|
|
|
|
# To remove leading spaces
|
|
|
|
sed -i -r 's/^\s+//g' file.txt
|
2013-08-31 11:46:33 +02:00
|
|
|
|
2014-10-19 17:43:43 +02:00
|
|
|
# To remove empty lines and print results to stdout:
|
2013-09-07 06:29:49 +02:00
|
|
|
sed '/^$/d' file.txt
|
2014-10-19 17:43:43 +02:00
|
|
|
|
|
|
|
# To replace newlines in multiple lines
|
|
|
|
sed ':a;N;$!ba;s/\n//g' file.txt
|