Turning a list items on lines into a horizontal list

I just realised I can use xargs to quickly turn a list of items into a horizontal list for further use on the command line.  Well of course that’s the fundamental purpose of xargs, but with echo I can do it without having xargs execute the actual command in question.

i.e.


cat my.csv | cut -d, -f 2 | xargs echo

Can take a column from a csv and turn it into a horizontal list, like,


12354
32132
77632
09211
99321

to


12354 32132 77632 09211 99321

Kind of a no brainer when you think about it, if only I thought of it more often.

Advertisements

One thought on “Turning a list items on lines into a horizontal list

  1. I’m always using shell to flatten lists 🙂

    $ echo `cut -d, -f 2 my.csv`

    another common idiom…

    $ for i in `cut -d, -f 2 my.csv`; do stuff $i; done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s