How to remove space between lines in linux

Instruction: Before running these command make backup of your original file.
# cat foo
hello

hi

this

that

#sed -i '/^$/d' foo
# cat foo
hello
hi
this
that

This tells sed to delete every line matching the regex ^$ i.e. every empty line. The -i flag edits the file in-place, if your sed doesn't support that you can write the output to a temporary file and replace the original:

#sed '/^$/d' foo > foo.tmp
#mv foo.tmp foo

How to Hide lines starting with # from file

# cat file
Testing
#Just testing

# egrep -v '^#|^$' file
#cat file

Testing

Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment