LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 01-18-2017, 01:48 PM   #1
liketheshell
LQ Newbie
 
Registered: Sep 2012
Posts: 20

Rep: Reputation: Disabled
Get value from list as well as count


Hello All,

Would somebody know how to get the value from a for list and associated count of submissions through a grep.

The below would give a me a count of submissions for each id in the list.

for i in MQR200B MQR200C MQR200D MQR200E MQR200F
do
logfile.txt |grep SUBMISSION | echo $i | grep -c $i
done

0
6084
10324
7200
10315

My desired output would have the values in the list next to the count

MQR200B 0
MQR200C 6084
MQR200D 10324
...

Many thanks
 
Old 01-18-2017, 02:01 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,278

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
man grep (-c, -f)
 
Old 01-18-2017, 02:09 PM   #3
liketheshell
LQ Newbie
 
Registered: Sep 2012
Posts: 20

Original Poster
Rep: Reputation: Disabled
Thanks for the feedback. That solution does not seem to work. Trying multiple ways, seems to result in output below

grep: MQR200B: No such file or directory
0
grep: MQR200C: No such file or directory
0
 
Old 01-18-2017, 02:22 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
Maybe:

Code:
for i in MQR200B MQR200C MQR200D MQR200E MQR200F
do
 printf " $i"
 grep -c $i logfile.txt
done
Not sure what the SUBMISSION bit was for,..
 
Old 01-18-2017, 02:46 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,278

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
Quote:
Originally Posted by liketheshell View Post
Thanks for the feedback. That solution does not seem to work. Trying multiple ways, seems to result in output below

grep: MQR200B: No such file or directory
0
grep: MQR200C: No such file or directory
0
Code:
grep -c -f /whatever/floats/your/boat /whatever/grinds/your/gears
 
Old 01-18-2017, 04:14 PM   #6
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
I am wondering why this doesn't already give an error:
Code:
....
do 
logfile.txt |grep SUBMISSION
...
 
Old 01-18-2017, 04:20 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
for i in MQR200B MQR200C MQR200D MQR200E MQR200F; do grep $i -c logfile.txt ; done
 
  


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
Count characters and list down the number bison72 Linux - Newbie 3 01-22-2013 11:34 AM
[SOLVED] MySql order by COUNT and list the total count countrydj Programming 3 07-19-2012 01:21 PM
Count the No.of Lines in a set of given file list kumar_eee Linux - General 2 09-21-2010 03:01 AM
directory list count saranraj Linux - Newbie 18 02-26-2010 04:05 AM
How to get list or count of unleased ips from dhcpd3? matiasquestions Linux - Networking 2 07-24-2008 03:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:03 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration