awk system batch operation

use awk command batch creation of files

awk 'BEGIN {do {++i; system("touch file_num_" i "_test") } while (i<9) }'

use awk command batch rename

ls | grep test | awk '{system("mv "$0" "substr($0,0,10)"")}' ​​​​

use awk command batch delete files

ls | grep -v '_sort' | grep -v '.lck' | awk '{system("rm -rf "$0"")}' ​​​​

use awk command to divide a file into multiple files

awk '{if(NR % 4==0){print $0 >>"ttt_0"}else if(NR % 4==1){print $0 >>"ttt_1"}else if(NR % 4==2){print $0 >>"ttt_2"}else if(NR % 4==3){print $0 >>"ttt_3"}}' test.log

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *