On Friday 30 January 2004 09:21, The Purple Tiger wrote:
On Thursday 29 January 2004 21:56, steve-ss wrote:
(grep year7 /etc/passwd | awk -F: '{print "mv /home/"$1" /home/year7/"$1}') | cat I don't understand it but it runs OK. Is there a quick one liner to explain how it works? Thanks again, Steve.
Okay, here we go [afaik :)] grep is a powerful pattern matching utility:
#grep year7 /etc/passwd goes through the file /etc/passwd and looks for the string "year7" and prints it to "stdout" [i.e. standard output so other programs can process the info, or display on screen] The " | " is known as a pipe through - basically, run the program to the left and feed the output to the program on the right.
awk is like grep iirc, but more powerful. the -F: runs a program, and the stuff after that in the apostrophes is the program itself. It prints: mv /home/ The $1 indicates take the first field from the output line from the previous program and insert it here, so if your paswd file had "bob" as the first field, then it would print "mv /home/bob" :)
If you follow in the same vein for the rest of it, then you get: mv /home/firstfield /home/year7/firstfield
then the lot is "piped through" cat which just displays it to the screen [like "type" on dos/windows]
Hopefully I haven't confused you more :g:
Jon
Now THIS is what i like!!! A short description what the fix/scrip/sollution does. It helps us illiterates to understand whats going on. I usaly dont run unexplained/undocumented scripts unless i get a halfdecent understanding of what it does. The way Jon explained the script is exemplary! VERY GOOD WORK!! -- /Rikard ------------------------------------------------------------------------------------ Rikard Johnels email : rikjoh@norweb.se Web : http://www.rikjoh.com Mob : +46 (0)735 05 51 01 ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 >