ooooh, neat
Oct. 18th, 2006 02:25 pmI was shown
I had a list of hosts in someList, with an unknown number of whitespace before and after each host, on which I wanted to perform someCommand -someFlag.
One of my co-workers told me to skip manually cleaning up the file and just pipe it through xargs.
Then, at my blank look, he explained xargs briefly and keyed the following into my terminal:
Which processed the list. No muss, no fuss. Sweeeeeet.
Unfortunately, the output was rather lengthy. So, I ran it again, piping the output through a grep for the particular field that I needed.
Presto.
xargs the other day as a means of regularizing data for input.I had a list of hosts in someList, with an unknown number of whitespace before and after each host, on which I wanted to perform someCommand -someFlag.
One of my co-workers told me to skip manually cleaning up the file and just pipe it through xargs.
Then, at my blank look, he explained xargs briefly and keyed the following into my terminal:
for hosts in `cat someList | xargs `; do someCommand -someFlag $hosts; doneWhich processed the list. No muss, no fuss. Sweeeeeet.
Unfortunately, the output was rather lengthy. So, I ran it again, piping the output through a grep for the particular field that I needed.
for hosts in `cat someList | xargs `; do someCommand -someFlag $hosts; done | grep someParticularFieldPresto.
Shiny!
Date: 2006-10-20 01:42 pm (UTC)