Some useful sed command

Remove all empty line:
sed '/^$/d'
In vim :

Remove or replace space and tabs:
sed 's/^[ \t]*//g'

Remove or replace all line return:
sed ':a;N;$!ba;s/\n//g'

Append a line after every line matching the pattern:
sed '/Sysadmin/a \ text' file

Insert Lines:
sed 'ADDRESS i\ text' file

Append at the end of line matching
sed 's/match.*/& text/' abcd.txt

Insert at the beginning:
sed 's/^/text/'

Append at the end:
sed 's/$/text/'

Remove the Ending char:
sed 's/.$//'

Remove ^M in vim :
With tr :
tr "\r" "\n"
And with sed :
sed -i -e 's/\r//g'

remove space at the beginning :
sed 's/^ *//g'

The following command deletes any trailing whitespace at the end of each line in vim :

Sed direcly in a file

2020-07-11 21:02:23


Add a Comment

Login or Register to post a Comment.