mirror of https://github.com/cheat/cheat.git
24 lines
673 B
Plaintext
24 lines
673 B
Plaintext
# To replace all occurrences of "day" with "night" and write to stdout:
|
|
sed 's/day/night/g' file.txt
|
|
|
|
# To replace all occurrences of "day" with "night" within file.txt:
|
|
sed -i 's/day/night/g' file.txt
|
|
|
|
# To replace all occurrences of "day" with "night" on stdin:
|
|
echo 'It is daytime' | sed 's/day/night/g'
|
|
|
|
# To remove leading spaces
|
|
sed -i -r 's/^\s+//g' file.txt
|
|
|
|
# To remove empty lines and print results to stdout:
|
|
sed '/^$/d' file.txt
|
|
|
|
# To replace newlines in multiple lines
|
|
sed ':a;N;$!ba;s/\n//g' file.txt
|
|
|
|
# Insert a line before a matching pattern:
|
|
sed '/Once upon a time/i\Chapter 1'
|
|
|
|
# Add a line after a matching pattern:
|
|
sed '/happily ever after/a\The end.'
|