SED Commands Cheat Sheet

Here is a cli commands cheat sheet for SED command, you can use this as a quick reminder for basic commands with a brief description for each of the commands.

What is SED command?

Add some data here

        # To replace all occurrences of "day" with "night" and write to stdout:
sed 's/day/night/g' 

# To replace all occurrences of "day" with "night" within :
sed -i 's/day/night/g' 

# 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' 

# To remove empty lines and print results to stdout:
sed '/^$/d' 

# To replace newlines in multiple lines:
sed ':a;N;$!ba;s/\n//g' 

# To insert a line before a matching pattern:
sed '/Once upon a time/i\Chapter 1'

# To add a line after a matching pattern:
sed '/happily ever after/a\The end.'
    

Check out the SED command documentation .


You can also check our MegaSh cheatsheet tool, that has 150+ searchable linux cheat sheets in one page, so you never forget a command as you work again

Check Also

Best AI tools list