LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 02-11-2011, 06:11 AM   #1
kakalig2007
LQ Newbie
 
Registered: Jul 2008
Posts: 11

Rep: Reputation: 0
showing word list without using "wc" commnad


Please tell me which command should I use to display count of words from a file, so that the filename is not displayed along with the word count.
 
Old 02-11-2011, 06:14 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You can just print the first column, by using awk to extract it, e.g.

$ wc -w file | awk '{print $1}'
 
Old 02-11-2011, 06:18 AM   #3
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,634
Blog Entries: 29

Rep: Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900
Putting cksum in Nylex's command produces the byte count though not the word count!?!
Code:
anisha@linux-uitj:~> cksum d.h | awk '{print $1}'
1462178974
 
Old 02-11-2011, 06:20 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Oops, I misread the question. I thought they just wanted to omit the filename in the wc output, rather than not using wc at all.
 
1 members found this post helpful.
Old 02-11-2011, 11:08 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
You can send the file on stdin instead of by name:
Code:
~/tmp$ wc -w numbers.txt 
10 numbers.txt
~/tmp$ wc -w < numbers.txt 
10
 
1 members found this post helpful.
Old 02-11-2011, 11:38 AM   #6
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,243

Rep: Reputation: 197Reputation: 197
Assuming you have the text file named Hamlet.txt:

Quote:
To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The Slings and Arrows of outrageous fortune;
Or to take Armes against a Sea of troubles...
you could obtain the list of the words using the command:

cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012

Quote:
To
be
or
not
to
be
that
is
the
question
Whether
'tis
nobler
in
the
mind
to
suffer
The
Slings
and
Arrows
of
outrageous
fortune
Or
to
take
Armes
against
a
Sea
of
troubles
to count the words you could use the following command:

cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012 | grep '.' -n

Quote:
1:To
2:be
3r
4:not
5:to
6:be
7:that
8:is
9:the
10:question
11:Whether
12:'tis
13:nobler
14:in
15:the
16:mind
17:to
18:suffer
19:The
20:Slings
21:and
22:Arrows
23f
24utrageous
25:fortune
26:Or
27:to
28:take
29:Armes
30:against
31:a
32:Sea
33f
34:troubles
since you'd like to know just the number of the words use the command:

cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012 | grep '.' -n | tail -n 1 | cut -d ':' -f 1

Quote:
34
The more effective method is to use mentioned above wc command but you refuse to use it.
 
  


Reply

Tags
shell


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 11:35 AM
[SOLVED] Scripting Help: Using "File1" as list of objects to search for in "File2" Asharru Programming 10 09-05-2010 07:53 PM
"Multicolumn" or "tiles", or even "list" icon view on desktop, in any DE? the dsc Linux - Desktop 3 02-20-2010 10:25 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Does Slackware have "lndir" commnad? buboleck Linux - Newbie 2 12-23-2003 01:05 PM


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