MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Interview Questions & Answers Complete Guide for Linux

Linux What is your experience with Linux? Explain what each of the following commands does and give an example on how to use it: Explain each field…

Read More

Grep and Sed Questions with Shell script

scmuser created the topic: grep and sed questions with shell script Search for a pattern with grep and sed and look for a file with find. Test…

Read More

Frequently Used Shell Script

rajeshkumar created the topic: Frequently Used Shell Script Shell scripts to convert file names to lower case and upper case To convert to lower case: #!/bin/sh for…

Read More

Check to see if a build is running or not

rajeshkumar created the topic: Check to see if a build is running or not All I need to do is check to see if a build is…

Read More

Shell Scripting Tutorials: Function

A Bash function is a named block of commands that takes arguments as $1, $2, … and $@, and hands results back through its output or its…

Read More

Shell Scripting Tutorials: Looping & Iteration statatement using for until

An until loop in shell scripting keeps running its body for as long as a test command fails (returns a non-zero exit status), and stops as soon…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x