LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 02-13-2006, 11:53 AM   #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, 12:03 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,506

Rep: Reputation: 116Reputation: 116
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, 12: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, 12:46 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,506

Rep: Reputation: 116Reputation: 116
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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 01:08 AM
word count pantera Programming 2 08-31-2004 07:23 AM
word count in a line pantera Programming 4 08-25-2004 01:14 PM
Really basic OOo or Staroffice Q re: word count Calum Linux - Software 8 06-04-2003 05:57 AM
Word count in paragraph - Open Office, Sutekh Linux - Software 10 04-19-2003 10:27 PM


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