LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-14-2006, 12:55 PM   #1
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
bash script - remove header row from csv file


I'm trying to write a script to automatically take our company phone directory every month and convert it to a palm database file so I have a complete updated directory with me.

Anyway, the script works great, but there's a row of garbage at the top of the file that I'm stumped by.

I've been googling around trying to figure out how to get rid of it and haven't found what I'm looking for. I'm sure there must be a simple awk or bash command that can just whack off the top row of a file, but I'm struggling to find it.

I can live with it, but I was thinking of releasing the phone directory to the rest of the company and would like it to be pretty flawless before I do so.
 
Old 08-14-2006, 01:25 PM   #2
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Original Poster
Rep: Reputation: 269Reputation: 269Reputation: 269
Never mind.
Code:
sed '1d' file.txt > file.csv
 
Old 08-14-2006, 01:26 PM   #3
burninGpi
Member
 
Registered: Mar 2006
Location: Fort McMurray, Canada
Distribution: Gentoo ~amd64
Posts: 163

Rep: Reputation: 30
You want to remove the first line of the file? Here's an awk script:
Code:
awk 'FNR>1{print}' file.txt
 
Old 08-14-2006, 01:27 PM   #4
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
sed -i '1d' /path/to/filename.txt
 
Old 08-14-2006, 01:39 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Alternately, sed '2,$p' /path/to/file
 
Old 08-30-2006, 12:05 PM   #6
Tim Retout
LQ Newbie
 
Registered: Dec 2004
Location: UK
Distribution: Debian
Posts: 21

Rep: Reputation: 15
Yet another alternative:

Code:
tail -n+2 /path/to/file > /path/to/output
Test with something like:

Code:
echo -e "foo\nbar\nbaz" | tail -n+2

Last edited by Tim Retout; 08-30-2006 at 12:08 PM.
 
  


Reply

Tags
awk, bash, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to remove files older than 3 days rust8y Linux - General 26 10-04-2012 09:26 AM
help with bash script: remove * to the last . in string drkstr Linux - Software 3 04-25-2006 05:54 PM
remove part of string in bash script crewblunts Programming 2 03-16-2006 06:54 PM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 03:01 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 09:23 PM


All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration