• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Unix shell script

I have created the file throygh unix shell script.
In that script I have fired the sql query on sqlserver and create the file.
There are 4 rows in query with '|' separated.
But in file after each record blank lines are available.
I do not that blank lines.
How can I remove it?
Please help !
0
digs developer
Asked:
digs developer
  • 3
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Post a sample of your output file and your desired output, that will help us solve your issue.

In general, you can remove empty lines in a shell script like this:

sed -i '/^$/d' <your_file>

or:

awk 'NF>1' <your_file> > <new_file>

The sed command will edit <your_file> and the awk output is redirected to <new_file>
0
 
sventhanCommented:
Try redirecting to another file

sed -e 's/ *$//g' file_name > file_name.temp
mv file_name.temp file_name
0
 
digs developerAuthor Commented:
thank you !
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
@sventhan - Your sed command is not removing empty lines. And sed -i is performing the replacement in the same file, no need for a temporary file :)
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Don't forget to close the question :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now