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
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND