awk script loop filter

#! / bin / bash 
content # progressive matching file, output 
# $ 1
the EPC inspection alarm content file messages in the $ 2 console to export the file list .scv $ 3 after filtering file to be saved name
IF [$ # -ne 3 ]; the then 
    echo  " USAGE UTF-8: $ 0 <messages in the EPC inspection alarm content file> <exported EPC list file> <filename filters to be saved> " 
    Exit 
fi 

for SN in $ ( awk  ' {Print $. 5} ' $ . 1 )
     do 
       # -F defined delimiter shell variables ' ' variable name ' "  
       awk -F ' , | ' '   ' /' ' $ the SN ' " / {Print $. 1 , $ 4, $ 6} '   $ 2 >>$3
    done
search_count=`awk '{print $5}' $1 | wc -l`
find_count=`cat $3| wc -l`
if [ $search_count -eq $find_count ];then
    echo -e "\033[32;1mAll searches found , Sum : ${search_count}    Please See $3 \033[0m"
else
    echo -e "\033[31;1mSearch Count ${search_count} ; Found  ${find_count}   Please See $3 \033[0m"
fi

Several methods cited the shell awk variable ============================

:"'$var'"

We used such an approach without changing 'enclosed awk program diet , foreigners are commonly written as. :

var="test"
awk 'BEGIN{print "'$var'"}'

The wording in fact, the single quotes single quotes into two sections, the middle shell variable in accordance with a direct reference to a shell variable, but if var contains spaces , in order shell ruled as not to break the space , it should used as follows :

= var " Thisis A Test " 

awk  ' the BEGIN {Print " '" $ var " ' "} '     (i.e. on both sides of shell variables can be combined with a pair of double quotes)

Two : export variables using ENVIRON [ "var"] form , (the ENVIRON is built in the environment variables awk array )

Such as :                                                                     

var="thisis a test";export $var

awk 'BEGIN{print ENVIRON["var"]}'

Three : Of course you can also use the -v option

Such as :

var="thisis a test"
awk –v nvar="$var"  'BEGIN{print nvar}'

Such systems put variable definitions became awk variable .

If this format is then awk awk 'script' filename shell may be variable such reference

awk 'script' awkvar="shellvar" filename
awk 'END{print awkvar}' awkvar="$shellvar" filename

============ awk references shell variable END =================

Guess you like

Origin www.cnblogs.com/zhangmingda/p/12455216.html