Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    4

    Question Unanswered: Removing the header from a file

    I have a text file that I am reading and outputting to another file after adding comma delimiters between each field. I have been able to do this part through a shell script using the echo function. I would also like to get rid of the header row in the new file within the same script. How can I do that?

    Original File:

    XXXX YYYYY ZZZZZ AAAAA
    123 456 789 00011
    345 678 233 00023


    New File:

    123,456,789,00011
    345,678,233,00023

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Try:
    Code:
    sed '1d' MyFile >NewFile
    mv NewFile MyFile
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Apr 2004
    Posts
    4
    Thanks! Works great!!

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    how about all with one awk statement from the original file:
    Code:
    nawk -v OFS="," 'FNR != 1 && $1=$1' originalFile.txt
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Jul 2004
    Posts
    45
    Just curious!!! how will you get rid of last line or footer???

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    to remove the last line with sed:
    Code:
    sed '$d' myFile.txt
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

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