This is great, I saw it somewhere the other day but can’t remember where. It is pretty simple too… sometimes when I do stuff on the command line with cut I try to run multiple commands on the output, but it never works cos I try to it with sed but with this method it works great.
Check it out:
for i in `ps auwx|grep hamstar|cut -f2 -d’ ‘`; do kill $i; done
That would kill all the processes that I have started under my username. Notice the red part is where it takes all the entries (puts each one into $i as it uses it, and the blue part is where it does something with the entries ($i again)). Adding kill to the start and ; to the end using sed would not work for this.
Ok that might a bit tricky for some of you, especially if you haven’t come across the miracle of piping yet, let me show you a simpler one.
for i in *; do echo $i; done
Basically another form of ls but thing of the things you can do with this. Rename from lowercase to uppercase:
for i in *; do mv $i `echo $i|tr [A-Z] [a-z]`; done
So its basically limitless to what you can do with this cool thing.
I also found another cool thing while writing this. Doing the following will covert all characters in a given file to lowercase or uppercase if you changed it:
dd file.txt conv=lcase