Operating System - HP-UX
1830933 Members
2051 Online
110017 Solutions
New Discussion

Re: removing text from a ascii file

 
Paul Rohde
Advisor

removing text from a ascii file

I have a log file that has alot of header info on it. I want to remove the header info while leaving the rest of the file.

For instance the header data is the first 10 lines. I want to delete the first ten lines and mail the rest of the file.

Is there a command that will remove the first ten lines, or a command that will cut out all the lines of a file except the first ten lines so I can redirect it to another file. The log file can have any amount of lines at any time.

This will be done in batch mode, from a shell script.

The file is an ascii text file.

Any help would be appreciated.
7 REPLIES 7
Vikas Khator
Honored Contributor

Re: removing text from a ascii file

Hi ,

Try tail +10
Keep it simple
Rita C Workman
Honored Contributor

Re: removing text from a ascii file

Here's one to remove the first 10 lines...

cat | sed 1,10d >

This will read your file...delete lines 1 thru 10 and output to the newfile

/rcw
Stefan Schulz
Honored Contributor

Re: removing text from a ascii file

The two commands i would use:

tail +10 infile > outfile

sed 1,10d < infile > outfile

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Klaus  Frank
Frequent Advisor

Re: removing text from a ascii file

Hi Paul

If you prefere awk try this:

awk ' NR > 10 { print $0 } ' filename

NR is linenumber.
awk offers a lot more optins on changing text files. see man awk !

Klaus
... we all can make it with a little help ...
Vincenzo Restuccia
Honored Contributor

Re: removing text from a ascii file

Edit the file in vi:
:1,10d
:wq!
Ralph Grothe
Honored Contributor

Re: removing text from a ascii file

Not that I have to add something to the respondents before me,
probably the most elegant solution is the first reply.
But the + flag is obsolete by now, so that you better go with the sed or awk solutions.

The only suggestion I have is to mail it in one go:

awk 'NR>10' /file/to/chop | mailx -s 'file chopped by 10 lines' you@your.account
Madness, thy name is system administration
Frederic Soriano
Honored Contributor

Re: removing text from a ascii file

Hi,

You can even do it shorter:

sed 1,10d | mailx -s root

Best regards,

Fred.