Solved Unix- Remove the blank line after ^L.

November 14, 2011 at 09:50:58
Specs: AIX
I have a large txt file that resides on my AIX server and i need to remove the blank line after each ^L character. I have been unsuccessful can anyone help?

Txt example file. I need to get rid of the blank line. The example below is the scenario throughout the 3mb file.

txtxtxtxtxxtxtxtxtxtxtxtxtxtxtxtx
^L

txtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxtxt


See More: Unix- Remove the blank line after ^L.

Report •

✔ Best Answer
November 15, 2011 at 10:01:33
This awk should do it. Once again, that is a real control-L (Use nawk if your OS is Solaris):

awk '{
if(match($0,"^L") > 0)
    {
    print $0
    # skip the next line if blank
    getline
    if(match($0,"^$") > 0)
       continue
    }

print $0
 }' batfile.txt > newbatfile.txt



#1
November 14, 2011 at 23:22:50
Here are two solutions:

First, this sed script replaces an actual control-L and a space with just an actual control-L:

sed 's/^L /^L/g' batfile.txt > newbatfile.txt

You probably cannot cut and paste this. In vi, to create an actual control-L while in edit mode, press a control-v (which signifies a special character is to be entered) and then press control-L

A second method is to use the ASCII octal value of control of a control-L as below:

sed 's/'"$(printf '\012')"' /'"$(printf '\012')"'/g' batfile.txt > newbatfile.txt

The above command you can cut and paste. This method works on my Solaris 9 box, but I cannot guarantee the portability.

Let me know if you have any questions.



Report •

#2
November 15, 2011 at 06:17:41
Thank you for your reply nails. I'm a bit confussed. Im trying to remove the blank line below the control-L ie ^L The blank line is below every ^L I have in this huge txt file and i need to remove every blank line below the ^L. Maybe i am missing something here? Thanks for your help.

Report •

#3
November 15, 2011 at 07:28:01
No, you are not missing anything - I am - like what your requirement is. Sorry.

Let me think about it, and I'll try to get a response to you today.


Report •

Related Solutions

#4
November 15, 2011 at 09:55:47
hi nails,

with the help of a friend i was able to use sed to make the change. Thank you for your time. See command below.

sed -e '/^L/{n;d;}' batchfile > batchfile2

NOTE: thats a control-L not a carrot L.

Cheers


Report •

#5
November 15, 2011 at 10:01:33
✔ Best Answer
This awk should do it. Once again, that is a real control-L (Use nawk if your OS is Solaris):

awk '{
if(match($0,"^L") > 0)
    {
    print $0
    # skip the next line if blank
    getline
    if(match($0,"^$") > 0)
       continue
    }

print $0
 }' batfile.txt > newbatfile.txt


Report •

#6
November 15, 2011 at 10:04:56
Thanks for all your help Nails!

Report •

Ask Question