LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-11-2008, 09:33 AM   #1
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
question about tr and newlines


Hey everyone,

I'm trying to extract words from a file and count their frequency of occurrence some unix commands. I've got it pretty well. I simply replace spaces with newlines, and then use 'uniq' to count up the frequencies. Problem is, I don't want to count the newlines. So, I want to get rid of the unnecessary newlines (not the newlines that put each word on its own line).

I thought using "tr -s '\n'" would do the trick, but it doesn't. Any suggestions?
 
Old 09-11-2008, 09:52 AM   #2
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
sorry... i probably should have put this in the programming forum
 
Old 09-11-2008, 09:53 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
You could use grep -v to remove empty lines. You might want to also convert tabs to newlines as well as spaces.
Code:
tr ' \t' '\n\n' infile | grep -v '^$' | ...
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question re: newlines retrovertigo Programming 4 07-06-2007 09:50 PM
Bash scripting question re: newlines retrovertigo Programming 1 07-06-2007 01:41 AM
Gaim newlines Napalm Llama Linux - Software 5 07-04-2005 02:09 PM
A perfectionistic question: Newlines in the HCL and Reviews page Bebo LQ Suggestions & Feedback 2 05-25-2004 02:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration