LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 05: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, 05: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, 05:18 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931Reputation: 931
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, 05: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, 10:08 AM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,695

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
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, 10:38 AM   #6
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
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 7 12-19-2015 01:03 AM
[SOLVED] Scripting Help: Using "File1" as list of objects to search for in "File2" Asharru Programming 10 09-05-2010 06:53 PM
"Multicolumn" or "tiles", or even "list" icon view on desktop, in any DE? the dsc Linux - Desktop 3 02-20-2010 09:25 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Does Slackware have "lndir" commnad? buboleck Linux - Newbie 2 12-23-2003 12:05 PM

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

All times are GMT -5. The time now is 11:23 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
Open Source Consulting | Domain Registration