unix - Search files and run a script on every result - Cont: -
i know how search pattern of files (gunzip files) in sub directories ( month wise / date wise - sub directories created). , then, execute script on found files. need populate filename along output tracking purpose , further analysis on particular files.
step1: example: searching files on pattern tt_detail*.gz.
find /cygdrive/c/test/ -name tt_detail*.gz
output#1:
/cygdrive/c/test/feb2014/tt_detail_20141115.csv.gz /cygdrive/c/test/jan2014/tt_detail_20141110.csv.gz /cygdrive/c//test/mar2014/tt_detail_20141120.csv.gz
step2:
zcat tt_detail*.gz | awk 'begin { fs=ofs=","} { if ($11=="10") print $2,$3,$6,$10,$11,$17}' >op_tt_detail.txt
cat op_tt_detail.txt
zzz,aaa,ech,1,10,xxx zzz,bbb,ech,1,10,xxx zzz,ccc,ech,1,10,xxx zzz,ddd,ech,1,10,xxx
thanks fedorqui
below script working fine without filename.
while ifs= read -r file awk 'begin { fs=ofs=","} { if ($11=="10") print $2,$3,$6,$10,$11,$17}' <(zcat "$file") >>op_tt_detail.txt done < <(find /cygdrive/c/test/ -name tt_detail*.gz)
have tried below command populate filename along output tracking purpose :
while ifs= read -r file awk 'begin { fs=ofs=","} { if ($11=="10") print $2,$3,$6,$10,$11,$17,filename}' <(zcat "$file") >>op_tt_detail.txt done < <(find /cygdrive/c/test/ -name tt_detail*.gz)
desired output:
zzz,aaa,ech,1,10,xxx,/cygdrive/c/test/feb2014/tt_detail_20141115.csv.gz zzz,bbb,ech,1,10,xxx,/cygdrive/c/test/feb2014/tt_detail_20141115.csv.gz zzz,ccc,ech,1,10,xxx,/cygdrive/c//test/mar2014/tt_detail_20141120.csv.gz zzz,ddd,ech,1,10,xxx,/cygdrive/c//test/mar2014/tt_detail_20141120.csv.gz
since filename not working *.gz files , should write" find /cygdrive/c/test/ -name tt_detail*.gz
" output file call output file script , don't have write access source files located server.
looking suggestions !!!
nice see using snippet i wrote in previous question!
i use this:
while ifs= read -r file awk -v file="$file" 'begin { fs=ofs=","} \ { if ($11=="10") print $2,$3,$6,$10,$11,$17, file}' \ <(zcat "$file") >>op_tt_detail.txt done < <(find /cygdrive/c/test/ -name tt_detail*.gz)
that is, -v file="$file"
give file name variable awk
. , use in print
command.
Comments
Post a Comment