?
Solved

wc -l question

Posted on 2007-07-20
7
Medium Priority
?
517 Views
Last Modified: 2010-04-20
wc -l File.txt is returning:
3 File.txt

That is, 3 separated by File.txt. Is there any way to just return 3?
0
Comment
Question by:soccerplayer
  • 3
  • 2
  • 2
7 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 200 total points
ID: 19535753
wc -l < File.txt
0
 
LVL 48

Expert Comment

by:Tintin
ID: 19535949
amit_q has given the best solution.  The other method is to do

cat File.txt | wc -l

0
 

Author Comment

by:soccerplayer
ID: 19537224
amit_g, your solution works but can you explain your solution a little bit? What it is doing? I would like to learn. Thanks.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 58

Expert Comment

by:amit_g
ID: 19537278
wc can count either the file given as the argument (the way you used it) and then it puts the filename in the output (as you saw). Another way to give input to wc (or for that matter to many Unix utilities) is to give it as stdin. < is shell redirection similar to >. < redirect stdin from a file while > redirect stdout to a file. Another way is to use pipe | as shown by Tintin.

Search google on Unix and stdin stdout and you will find many articles that explain this in details - some with visuals also.
0
 

Author Comment

by:soccerplayer
ID: 19541322
I know about the redirection operator but my question is, why would using the redirection operator cause the final output to be:
0

instead of:
0 File.txt
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19541446
That is how wc produces its output. Most likely reason is that when input is from stdin instead of from a file, the filename is unknown.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 19541858
It's a similar deal for grep.  

When you direct STDIN or pipe STDOUT to STDIN, then wc doesn't report a filename as it's been given a file stream rather than a file name.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question