Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2002
    Posts
    4

    Unanswered: 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

  2. #2
    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.

  3. #3
    Join Date
    Oct 2002
    Posts
    4
    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

  4. #4
    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?

  5. #5
    Join Date
    Oct 2002
    Posts
    4
    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

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •