I have a script which generates several output files and use these output files during runtime.Following are the some of the files generated by the script: apple.txt, section_fruit_out.csv, section_fruit_out_lookup.csv, food_lookup.csv, section_fruit_lookup.csv.I have a code phrase as below:nawk 'FNR == NR && NF!=0 {x[$1] = $1; next;} {FS=OFS=,} FNR>1{if ($2 in x) {($6 = apple)} } 1' apple.txt section_fruit_out.csv > section_fruit_out_lookup.csv nawk 'BEGIN { FS = OFS = ,; } FNR == NR { x[$1] = $2; next; } { if ($7 in x && $6 == ) { $6 = x[$7]; } else if ($6 ==  && $7 != ) { $6 = TO_BE_DEFINED } } 1' food_lookup.csv section_fruit_out_lookup.csv  > section_fruit_lookup.csvThis code phrase mainly handles the expected job. But the script does not work as expected if the apple.txt file is empty (this file is generated by database queries).  If the apple.txt file is empty, the output file (section_fruit_out_lookup.csv) of the first nawk section generated also empty. Since section_fruit_out_lookup.csv generated empty and it is used by the second nawk phrase, the second nawk phrase also generates empty output file (section_fruit_lookup.csv).How can I bypass first nawk phrase if the apple.txt file is empty and make the second nawk phrase to use section_fruit_out.csv file instead of using the file: section_fruit_out_lookup.csv?
Bypass a nawk snippet if the input file is empty
bash;shell;awk
there is a test function for zero size file.if test -s apple.txtthen     ## apple.txt non empty    code ...else    ## file emptyfi