Following is a neat trick for pulling a document through awk from inside of Vi. Say you generate a file by typing:
ls -l > myfile
"myfile" then contains like:
-rw-rw-r-- 1 joat joat 610 Oct 29 10:28 whois
You can then generate a list of shell commands by typing:
:1,.!awk '{print "cp",$9,$9 ".bak"}'
An alternative to this is:
:%!awk '{print "cp",$9,$9".bak"}'
This takes the ninth field in each row and inserts it into an output line with the format of
cp whois whois.bak
Source: UNIX IN THE ENTERPRISE newsletter for 13 March 2003.
No comments:
Post a Comment