The shell command can be executed directly in awk.
[Plain]View PlainCopy
- [Email protected]:~$ Touch A
- [Email protected]:~$ Touch b
- [Email protected]:~$ cat A.txt
- A
- B
- [Email protected]:~$ awk ' {cmd= ' rm ' $0;system (CMD)} ' A.txt
- [Email protected]:~$ ls
- A.txt dd important MySQL py testdata
- daemon.py Desktop Installer mysql_install_db.sh Stu
- Data DFADSFADFADF jdk1.6.0_33 Public stu.txt
- [Email protected]:~$
We assemble the commands in awk and finally execute them using system (). Read in a file name each time and delete the file.
----------------------------------------
Below we use awk to execute commands to create some files.
[Plain]View PlainCopy
- [Email protected]:~$ awk ' Begin{count=10;i=0;while (i<count) {cmd= "touch" I ". txt"; I++;system (CMD)}} '
- [Email protected]:~$ ls
- 0.txt 4.txt 8.txt dd jdk1.6.0_33 py
- 1.txt 5.txt 9.txt Desktop MySQL Stu
- 2.txt 6.txt daemon.py Important mysql_install_db.sh Stu.txt
- 3.txt 7.txt Data Installer public testdata
You can use System to execute complex shell commands in awk