Thursday, 27 August 2009

Random Musings - Day #239

More one-liners
No, this is not comedy but there are so many ways to kill a dead donkey. All these one-liners do the exact same thing and that's add a tab and 'Y' at the end of each line in a file...

for I in `cat t.txt`; do echo -e "$I\tY"; done

for I in `cat t.txt`; do printf "%s\tY\n" $I ; done

cat t.txt | xargs -i echo -e "{}\tY"


I prefer using the for construct in shell, as I can remember that and you can find a way of doing things with it. That's just a personal preference. Here's another example, generating IP address on-the-fly and look the dns name up.

for I in $(seq 255); do host 192.168.0.$I; done

No comments: