PDA

View Full Version : How to remove my header


pin
10-04-02, 16:42
Hi,

I would like to remove the header of the file. The header format
is as follow:
<blank line>
Name: abc
Start Time: 04/02/02 18:00
End Time: 04/02/02 19:00
Period: 60
<blank line>

How can I delete the above header lines (including the blank one)?

Thanks in advance,
Pin

TioTony
10-04-02, 16:45
sed 'd 1,6' original_file.txt > new_file.txt

new_file.txt will not contains the first 6 lines. I am assuming you are on Unix.

pin
10-04-02, 16:51
Originally posted by TioTony
sed 'd 1,6' original_file.txt > new_file.txt

new_file.txt will not contains the first 6 lines. I am assuming you are on Unix.

I cannot hard-code the line number to be removed. The header could
include more headers such as "TIME ZONE:..." and "OTHERS: ..."

Any ideas?

Thanks,
Pin

TioTony
10-04-02, 16:55
What is used to delimit the header then? Will it always be between 2 blank lines and not include any blank lines, etc?

pin
10-04-02, 17:05
Originally posted by TioTony
What is used to delimit the header then? Will it always be between 2 blank lines and not include any blank lines, etc?

At this time, I would say the header is between two blank lines.
However, if you know to delete those lines without using the blank lines
as the delimiter, please let me know too...

Thanks,
Pin

TioTony
10-05-02, 01:42
To easily remove the lines using a shell scirpt you will have to have some sort of delimiter. The problem is if those delimiters appear elsewhere in the source, it makes the issue more complex. For example, based on the current blank line delimiters you can use someting as simple as this:

sed '/^$/,/^$/D' original_file.txt

This will remove everything between and including the blank lines. The problem is if you have other blank lines, it is likely to delete other things as well.

A better route may be to write a perl script that reads the file and removes the lines that match common headers. This too can be an issue if the header text appears elsewhere in the source.

Not that this forum isn't great, you might want to try www.unix.com or www.perlmonks.org. Both are very helpful.