Computing.Net > Forums > Unix > Delete first line of a file

Delete first line of a file

Reply to Message Icon

Original Message
Name: covina
Date: October 6, 2006 at 12:30:03 Pacific
Subject: Delete first line of a file
OS: AIX 5.2
CPU/Ram: 512
Model/Manufacturer: IBM
Comment:

How do i delete first line of a file. The file starts with page break ^L. The first line contains the page break ^L. The file may have multiple pagebreaks and I don't want to delete from the file. I want answers in unix shell script, using sed or nawk commands or anyting simpler than that.

Any help will be appreciated.


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: October 6, 2006 at 12:42:06 Pacific
Reply: (edit)

This simple sed command deletes the first line, no matter what the line contains:

sed '1d' data.file > mynewdata.file


Report Offensive Follow Up For Removal

Response Number 2
Name: James Boothe
Date: October 6, 2006 at 13:39:35 Pacific
Reply: (edit)

Typically, the formfeeds occur at the beginning of the first line of each page. So if you delete the entire line, it will cause the first page to be missing the first line, and all remaining lines on that page will move upward one line.

To delete only the Ctrl-L, and leave the first line there (even if otherwise blank), you can do:

sed 1s/^L// data.file > mynewdata.file

(and key that as an actual Ctrl-L)

or you can use the \f designator:

sed 1s/"\f"// data.file > mynewdata.file


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Delete first line of a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge