If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to remove my header

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-02, 15:42
pin pin is offline
Registered User
 
Join Date: Oct 2002
Posts: 4
How to remove my header

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
Reply With Quote
  #2 (permalink)  
Old 10-04-02, 15:45
TioTony TioTony is offline
Registered User
 
Join Date: Sep 2002
Location: Orange County, CA
Posts: 9
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.
Reply With Quote
  #3 (permalink)  
Old 10-04-02, 15:51
pin pin is offline
Registered User
 
Join Date: Oct 2002
Posts: 4
Quote:
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
Reply With Quote
  #4 (permalink)  
Old 10-04-02, 15:55
TioTony TioTony is offline
Registered User
 
Join Date: Sep 2002
Location: Orange County, CA
Posts: 9
What is used to delimit the header then? Will it always be between 2 blank lines and not include any blank lines, etc?
Reply With Quote
  #5 (permalink)  
Old 10-04-02, 16:05
pin pin is offline
Registered User
 
Join Date: Oct 2002
Posts: 4
Quote:
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
Reply With Quote
  #6 (permalink)  
Old 10-05-02, 00:42
TioTony TioTony is offline
Registered User
 
Join Date: Sep 2002
Location: Orange County, CA
Posts: 9
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On