Saturday, November 6, 2010

Delete empty lines into a file

Problem - you have a file that has a huge number of records and in between you have
empty lines.
This is my example.txt file:
asd

asd
as


sd
as

asd

asd

sd
g
To take the spaces off you have at least two simple tools to do it.
  • sed with this tool you can achieve your goal just by doing this - open a command line prompt and type the following
    linux$ cat example.txt | sed -e '/^$/d' you will see on your screen the following
    asd
    asd
    as
    sd
    as
    asd
    asd
    sd
    g
    
  • grep with this we use a trick saying that we don't want certain patterns from the file - the empty lines - open a command line prompt and type the following
    linux$ grep -v '^$' example.txt
  • asd
    asd
    as
    sd
    as
    asd
    asd
    sd
    g
    

0 comments: