0

Hi i ve been trying to read records from a final_customer_total.txt which contains details like size of processed files. I used "nawk" command to read the final_customer_total.txt to calculate total size processed and then store the total sum into another file .

variable t= size of unprocessed files
for example let

t=1000

input file :

file1 100
file2 250
file3 300

expected output:

Total size needs to be processed : 1650

actual output:

file1 100
file2 250
file3 300
Total size needs to be processed : 1650

my concern content of inupt file also coming in output which i dont want!!
below is the command i tried

cat final_customer_total.txt |nawk '{total = total + $1} END{printf ("\nTotal size :"(total + t)/1024/1024/1024" GB")}'t=$t >>customer_total_size.txt

when i tried with "awk" its getting errored
Error :awk bailing out near line 1

skaffman
  • 398,947
  • 96
  • 818
  • 769
prabhakar
  • 55
  • 1
  • 6
  • Consider editing your post to show sample input data and expected output AND your current output and why it is wrong ALONG with any system error messages that are generated. It's too hard to tell what you are trying to accomplish based on above description. Good luck. – shellter Jan 04 '12 at 17:53
  • Shouldn't you be adding the value of `$2`? Your reported output also doesn't match what you describe in other respects. – tripleee Jan 21 '12 at 16:28
  • 1
    The `t=$t` should be separated from the program by at least a space. That would be the source of the syntax error. Whether you can pass the `var=value` after the program depends on `nawk`; consult its manual page. – Jonathan Leffler Jan 21 '12 at 16:53

1 Answers1

1

I suspect what you want to be:

nawk -v t=$t '
{
    total = total + $1
}
END {
    printf ("Total size needs to be processed: %d GiB\n",(total+t)/1024/1024/1024)
}' final_customer_total.txt > _cts.txt
mv final_customer_total.txt final_customer_total.txt.old
mv _cts.txt final_customer_total.txt
jlliagre
  • 29,783
  • 6
  • 61
  • 72