LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-13-2006, 12:53 PM   #1
DiagonalArg
LQ Newbie
 
Registered: Mar 2004
Posts: 23

Rep: Reputation: 15
Word count with grep


Hi.
I've got a text file with some data in it and I want to know how many times the letter 'x' occurs in it, my problem is that x occurs many times on one line so I can't use grep -c.
What's the best way to do this? I'm sure there must be a simple solution, but I can't seem to find it!
Thanks for your help.
 
Old 02-13-2006, 01:03 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Code:
cat file | tr -d -c "x" | wc -c
This uses tr to delete all non-x characters and wc to count the xs.
 
Old 02-13-2006, 01:14 PM   #3
DiagonalArg
LQ Newbie
 
Registered: Mar 2004
Posts: 23

Original Poster
Rep: Reputation: 15
Thanks! I'm quite pleased to see it wasn't a really obvious solution that I'd missed.
 
Old 02-13-2006, 01:46 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Nope, not terribly obvious. But I do like my shell tricks.
 
  


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
I can't find WORD COUNT in Open office! ahh where is it/ mr_coffee Linux - Newbie 9 02-17-2009 02:08 AM
word count pantera Programming 2 08-31-2004 08:23 AM
word count in a line pantera Programming 4 08-25-2004 02:14 PM
Really basic OOo or Staroffice Q re: word count Calum Linux - Software 8 06-04-2003 06:57 AM
Word count in paragraph - Open Office, Sutekh Linux - Software 10 04-19-2003 11:27 PM


All times are GMT -5. The time now is 07:41 AM.

Main Menu
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