LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 09-12-2010, 11:17 AM   #1
findme.krish
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Rep: Reputation: 0
Multiple grep outputs appended to single row of CSV file


how to update a series of values from multiple grep commands outputs to be appended to a single row of a csv file?
Work on a linux envir. The values from grep output will be numeric values.

Output sold look like:

1,3,4,5,7,0,5


Each of these values will be odtained from multiple grep commands piped with wc -l

Is it possible to update a single row of a csv file if so pleas ehelp me with the command to be used to redirect the output into the csv file
 
Old 09-12-2010, 12:50 PM   #2
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Something like this?:
((grep a * | wc -l; grep b * | wc -l) | tr '\n' ','; echo) >> bash.rocks.csv

Last edited by J_Szucs; 09-12-2010 at 12:57 PM.
 
Old 09-12-2010, 01:07 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
Code:
((grep a * | wc -l; grep b * | wc -l) | tr '\n' ','; echo) >> bash.rocks.csv
Just one minor improvement suggestion; use 'grep -c', save yourself
the invocation of 'wc'.

Code:
((grep -c a *; grep -c b *) | tr '\n' ','; echo) >> bash.rocks.csv
Cheers,
Tink

Last edited by Tinkster; 09-12-2010 at 01:08 PM.
 
Old 09-12-2010, 01:19 PM   #4
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Hi Tinkster! In this very example (when greping files) your modification gives different results.
However, in general "grep -c" is in fact better, and should be preferred over "grep | wc -l".

Last edited by J_Szucs; 09-12-2010 at 01:27 PM.
 
Old 09-12-2010, 01:24 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
My bad - still waking up ... it would work for individual files.
With the * it won't, as it doesn't do summaries. 'wc -l' is
indeed the way to go :}


Cheers,
Tink
 
Old 09-12-2010, 06:56 PM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,202

Rep: Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796Reputation: 1796
Or we could use a single awk:
Code:
awk '/a/{sum[0]++}/b/{sum[1]++}END{while(i <= 1)printf sum[i++]","}' file
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for software to convert multiple csv files to a single xml file Rocket-boy Linux - Software 6 10-28-2009 10:03 AM
Paste each single row from n separate text files into a new file containing n rows Mike_V Programming 11 04-27-2009 11:51 PM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 11:05 AM
C++ read csv file row into vector taban1 Programming 3 11-08-2004 02:01 PM


All times are GMT -5. The time now is 08:25 PM.

Main Menu
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