LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 10-12-2011, 10:27 PM   #1
dan-e
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: 0
Question Help! Count lines of output using wc -l


Hi all,

I need to run a bunch of commands seperated by ; but then count the total lines of output. Pipes and redirection don't seem to be helping me. Anyone know how I can do this properly:

ls /usr/bin/nslookup | ls /usr/sbin/lsof | ls /sbin/ifconfig | ls /usr/sbin/dmidecode | ls /sbin/ethtool | ls /bin/netstat | wc -l

... assuming all files exist I would like to see '6' as the result. But I get '1' because it's not aggregating the output all the way to the wc. Same result if I use & or > between commands instead of |

Help?
 
Old 10-12-2011, 10:48 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Code:
ls -1 /usr/bin/nslookup /usr/sbin/lsof /sbin/ifconfig /usr/sbin/dmidecode /sbin/ethtool /bin/netstat | wc -l
 
1 members found this post helpful.
Old 10-12-2011, 10:54 PM   #3
dan-e
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: 0
heh, well that simplifies things. Thankyou sire!
 
Old 10-12-2011, 11:34 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Do you want to combine the output of a group of commands, so the output of all can be redirected (or used as in `wc -l)?

You can group the commands by either executing them in a subshell (...) or grouping them inside curly brackets. The output of each statement inside will be effected by redirecting STDOUT outside the braces or parentheses.
 
  


Reply



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 lines from file s_linux Red Hat 4 06-29-2010 06:33 PM
count lines and words lipun4u Linux - Newbie 2 02-15-2010 01:39 AM
script to count lines kalimat Programming 16 12-15-2008 04:09 AM
count lines beginning with 50 chloraldo Programming 3 08-18-2006 08:30 AM
command to count how many lines in a file? dr_zayus69 Linux - Software 3 01-06-2005 10:42 AM

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

All times are GMT -5. The time now is 12:42 PM.

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