LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-12-2009, 10:40 AM   #1
briana.paige
LQ Newbie
 
Registered: May 2009
Location: Canada
Posts: 14

Rep: Reputation: 0
Remove every fourth line from CSV file?


Hi,

I have a large csv file which has data for every 15 minutes and I need only the hourly data. I would like to keep the first line, delete the next three lines, keep the fourth etc...

Sample of the orig data:

Code:
01/01/2009	0:00:57	sleep	84	8.4	-13.11
01/01/2009	0:16:12	sleep	84	8.4	-13.11
01/01/2009	0:31:27	sleep	84	8.4	-13.11
01/01/2009	0:46:42	sleep	84	8.4	-13.11
01/01/2009	1:01:57	sleep	84	8.4	-13.11
01/01/2009	1:17:12	sleep	84	8.4	-13.11
01/01/2009	1:32:27	sleep	84	8.4	-13.11
01/01/2009	1:47:42	sleep	81	8.1	-13.28
01/01/2009	2:02:57	sleep	81	8.1	-13.28
Desired output from above data:

Code:
01/01/2009	0:00:57	sleep	84	8.4	-13.11
01/01/2009	1:01:57	sleep	84	8.4	-13.11
01/01/2009	2:02:57	sleep	81	8.1	-13.28
A simple awk or bash command would suffice as I only need to perform this operation on 1 or 2 files.

Any help is appreciated!
Thanks.
 
Old 08-12-2009, 10:49 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
sed -n '1~4p' input
Prints every 4th line. Add -i to make the changes permanent.

See http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html
 
Old 08-12-2009, 11:06 AM   #3
briana.paige
LQ Newbie
 
Registered: May 2009
Location: Canada
Posts: 14

Original Poster
Rep: Reputation: 0
Works like a charm, exactly what I needed! Thank-you so much!
 
Old 08-12-2009, 11:07 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
No problem

If you want to change the starting line, change the 1 to the line you want to start from. Likewise change 4 to 8 if you want it every 2 hours instead.

I'm sure there is an awk solution too, but if this works, so much the better. It's not exactly the longest command ever, either
 
  


Reply


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
replace line in CSV file and rename file connected to that name wademac Linux - Newbie 3 07-15-2009 02:09 PM
Erase first line of a csv file imkornhulio Programming 2 02-07-2009 07:28 AM
Convert a number on each line to CSV file OlRoy Programming 9 08-20-2008 12:05 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 10:15 PM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 12:05 PM


All times are GMT -5. The time now is 10:16 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