Unix shell script

Posted on 2014-08-11
Last Modified: 2014-08-18
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 !
Question by:digs developer
    LVL 37

    Expert Comment

    by:Gerwin Jansen
    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>


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

    The sed command will edit <your_file> and the awk output is redirected to <new_file>
    LVL 18

    Expert Comment

    Try redirecting to another file

    sed -e 's/ *$//g' file_name > file_name.temp
    mv file_name.temp file_name

    Author Comment

    by:digs developer
    thank you !
    LVL 37

    Expert Comment

    by:Gerwin Jansen
    @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 :)
    LVL 37

    Accepted Solution

    Don't forget to close the question :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now