bashawkgawk

What does ">!" do in bash or nawk?


I am translating a GAWK script into a C# program and I don't know what part of the GAWK script means. I've got the rest of the script figured out but I can't seem to find where to look for the rest of these commands.

I don't have an example of the other .tg files that its reading so I'm copying it blind and I need to get it right.

These are the lines:

date +"Report prepared %a %b %e %T %Y" >! $XTRAFILE
set ntg=`awk '\!/^#/{if(NF)print}' *.tg ad_tgs | wc -l`

Questions:

  1. Am I right in assuming that it puts the ">!" puts the "Report prepared" at the top of the $XTRAFILE?

  2. Also, I don't know what the "%a %b %e ..." is.

  3. Finally, is the line starting with "set ntg" counting the lines in the ad_tgs file?


Solution

    1. Am I right in assuming that it puts the ">!" puts the "Report prepared" at the top of the $XTRAFILE?

      >! came from csh and tcsh, will write stdout to file, overwriting any existing file

      Read More Here

    2. Also, I don't know what the "%a %b %e ..." is.

      %a locale's abbreviated weekday name (e.g., Sun)

      %b locale's abbreviated month name (e.g., Jan)

      %e day of month, space padded; same as %_d

      %T time; same as %H:%M:%S

      %Y year

      Read more Here

    3. Finally, is the line starting with "set ntg" counting the lines in the ad_tgs file?

        set ntg=`awk '\!/^#/{if(NF)print}' *.tg ad_tgs | wc -l`
      

      Prints all records/rows, which does not start with char # and has at least 1 field from all files, whos extension is .tg and file ad_tgs and | wc -l count number of lines which awk printed, and finally store number of lines in variable ntg