LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 11:55 AM   #1
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
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, 12:25 PM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Original Poster
Rep: Reputation: 281Reputation: 281Reputation: 281
Never mind.
Code:
sed '1d' file.txt > file.csv
 
Old 08-14-2006, 12: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, 12: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, 12:39 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Alternately, sed '2,$p' /path/to/file
 
Old 08-30-2006, 11:05 AM   #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 11:08 AM.
 
  


Reply

Tags
awk, bash, sed



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 08:26 AM
help with bash script: remove * to the last . in string drkstr Linux - Software 3 04-25-2006 04:54 PM
remove part of string in bash script crewblunts Programming 2 03-16-2006 05:54 PM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 02:01 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 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
Open Source Consulting | Domain Registration