Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a script that inputs a file and echos its contents with linebreaks removed - "word wrapped" so to speak.

I've tried:

find $HOME '$1' | while read line; do echo "${line}"; done

but it just returns nothing.

share|improve this question
up vote 9 down vote accepted

Try doing this:

echo $(cat $1)
share|improve this answer
Perfect, thanks! – southpointingchariot Sep 13 '12 at 0:35
Glad I could help you out finding one-out-of-many-ways-to-get-there, but try Googling a bit more next time. This is what I got as a second result popping up using the keywords bash, line, end, remove. – gertvdijk Sep 13 '12 at 0:46

I found this relevant answer in stackoverflow:

The quickest way appears to be using tr:

tr '\n' ' ' </your/file

or for your example:

cat `find $HOME '$1"` | tr '\n' ' '

To learn more about the tr command do, of course, man tr.

The stackoverflow anser contains ways to do this with sed (would have been my first choice, but sed is very line-oriented and getting it to not interpret line breaks as field delimiters is arcane) and a way using read and bash, close to your initial approach.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.