You can use System to execute complex shell commands in awk

Source: Internet
Author: User

The shell command can be executed directly in awk.

[Plain]View PlainCopy
  1. [Email protected]:~$ Touch A
  2. [Email protected]:~$ Touch b
  3. [Email protected]:~$ cat A.txt
  4. A
  5. B
  6. [Email protected]:~$ awk ' {cmd= ' rm ' $0;system (CMD)} ' A.txt
  7. [Email protected]:~$ ls
  8. A.txt dd important MySQL py testdata
  9. daemon.py Desktop Installer mysql_install_db.sh Stu
  10. Data DFADSFADFADF jdk1.6.0_33 Public stu.txt
  11. [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
  1. [Email protected]:~$ awk ' Begin{count=10;i=0;while (i<count) {cmd= "touch" I ". txt"; I++;system (CMD)}} '
  2. [Email protected]:~$ ls
  3. 0.txt 4.txt 8.txt dd jdk1.6.0_33 py
  4. 1.txt 5.txt 9.txt Desktop MySQL Stu
  5. 2.txt 6.txt daemon.py Important mysql_install_db.sh Stu.txt
  6. 3.txt 7.txt Data Installer public testdata

You can use System to execute complex shell commands in awk

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.