Awk and awk commands
Awk usage:
Move file: ls-lrt | awk '{if (substr ($20111029, 8) = '000000' & substr ($, 26, 3) = 'unl ') print "mv" $8 "/home/etl/data/interface;"} '| ksh
Sum: awk '{sum + = $1} END {print sum }'
Delete a file: ls-lrt | awk '{if (substr ($20111029, 8) = '000000 ') print "rm" $8 "/home/etl/data/interface;"} '| ksh
Find./-name "* 20111113 *" | awk '{print "rm" $1}' | ksh
Find file: find. -name "* sms20111201 *. unl "| xargs awk-F' |'' {if ($39 = '-1') print FILENAME "|" $0 }'
Awk-F Problems
-F indicates the delimiter of the FS Field. The default Delimiter is space.
If you want to change the output field separator to OFS (the output field separator, the default is space), as shown in
Echo a B c d | awk '{OFS = "|"; print $1, $2, $3, $4 }'
However, the output result of $0 is invalid.
So there are two methods:
1. awk '{OFS = "|"; if ($5 = "0") print $1, $2, $3, $4, $5, $6, $7, $8, $9, "this file is blank"} 'bb | tee cc
2. Because ls-l Results contain not only spaces but also tabs (\ t), you can use the following statements to meet your requirements.
Awk '{if ($5 = "0 ") print $0} 'bb | perl-pe '{s/[\ t] +/\ |/g}' | tee cc
Awk-F Problems
-F indicates the delimiter of the FS Field. The default Delimiter is space.
If you want to change the output field separator to OFS (the output field separator, the default is space), as shown in
Echo a B c d | awk '{OFS = "|"; print $1, $2, $3, $4 }'
However, the output result of $0 is invalid.
So there are two methods:
1. awk '{OFS = "|"; if ($5 = "0") print $1, $2, $3, $4, $5, $6, $7, $8, $9, "this file is blank"} 'bb | tee cc
2. Because ls-l Results contain not only spaces but also tabs (\ t), you can use the following statements to meet your requirements.
Awk '{if ($5 = "0 ") print $0} 'bb | perl-pe '{s/[\ t] +/\ |/g}' | tee cc