Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Remove blank line using Grep and sed

scmuser created the topic: Remove blank line using Grep and sed
Hi,

How do you remove blank line using grep and sed in shell scripting?

rajeshkumar replied the topic: Re: Remove blank line using Grep and sed

grep -v "^$" filename > newfilename

The ^$ within the quotes is a regular expression: ^=beginning of line, $=end of line, with no characters between.

To store output to another file use redirection operator:

$ sed ‘/^$/d’ /tmp/data.txt > /tmp/output.txt

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re: Remove blank line using Grep and sed
The above script will work only if you have no character in the blank line but most of the time it can happen that Tab can be possle in blank line….

so for this situation u should try following..

sed '/^[PRESS TAB]*$/d' filename

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x