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 > Removing the header from a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-04, 16:24
Bkhanna Bkhanna is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Question 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
Reply With Quote
  #2 (permalink)  
Old 08-10-04, 16:38
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
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
Reply With Quote
  #3 (permalink)  
Old 08-10-04, 16:55
Bkhanna Bkhanna is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
Thanks! Works great!!
Reply With Quote
  #4 (permalink)  
Old 08-10-04, 17:03
vgersh99 vgersh99 is offline
Registered User
 
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> |
+-----------------------+
Reply With Quote
  #5 (permalink)  
Old 08-10-04, 17:42
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
Just curious!!! how will you get rid of last line or footer???
Reply With Quote
  #6 (permalink)  
Old 08-10-04, 17:46
vgersh99 vgersh99 is offline
Registered User
 
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> |
+-----------------------+
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