6093 comments
2357 subscribers
6238 on Twitter
Subscribe! Feed reader E-mail

There’s more than one way to do it — linux

The original problem:

Hi,

I have a file in this format of words:

joe jill bill bob frank tom harry

and want to convert the file to this format:

joe
jill
bill
bob
frank
tom
harry

Is there an easy way to this? The file I have has hundreds of entries.
Thanks
Mike

Several proposed solutions

for word in `cat file`; do; echo $word; done > new_file
for x in `cat file`; do echo $x; done
sed -ri 's/[ \t]+/\n/g' file
tr ' ' '\012' < infile > outfile
fmt -w 1 filename > newfile
perl -p040 -l12 -e 'chomp' filename
perl -p040 -e 's/\s/\n/' filename
Short URL: http://sachachua.com/blog/p/1210

On This Day...

  • 2011: Decision review: Marrying W- — W- and I celebrated our first wedding anniversary last Sunday. It’s been a fantastic year! Time to review just how [...]
  • 2010: Lotus Notes mail practices — Here is a partial list of interesting practices I’ve seen, which I can compile into an internal or external wiki [...]
  • 2008: I’m so sorry! — I got caught up in IBM’s Innovation Jam, and I hadn’t realized that my blog was somewhat broken. Oops. I’ve disabled a [...]
  • 2007: Weekly review — The highlights of my week were the conversations I had. From hot chocolate at Farcoast with Driss (whom I’d last met [...]
  • 2005: More thoughts about Google and projects — I’ll keep Google internships in mind, as I really have AJAX and other fun Web stuff on my to-learn list. I [...]
  • 2005: Enthusiasm — From Year to Success: The source of the word “enthusiasm” comes from the Greek word enthousiasmos, which ultimately comes from the adjective [...]
  • 2003: Java Games tutorial #3 – Creating a Stand-alone Graphics Application — http://www.programmersheaven.com/articles/userarticles/mark/tut3/tut3_1.htm The tutorial uses BlueJ as an environment. Interesting…
  • 2003: NNTP access — Ani Dido Sevilla: Apparently the only way you can have access to Usenet these days from here is via groups.google.com. Some [...]
  • 2003: John Wiegley’s ledger — From John Wiegley, Emacs ubercoder: I’ve traded 60 Mb on my laptop for 60 Kb. How can you, too, lose three [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!