[Ilugc] Doubt in awk script

Mrugesh Karnik mrugeshkarnik at gmail.com
Fri Oct 12 23:44:04 IST 2007


On Friday 12 Oct 2007 12:10:56 Ashok Antony wrote:
> hi all
>
>
> in the below script, could any one explain me the usage of  '1'
>
> awk 'BEGIN{OFS=FS=",";c=1}
>     {
>      n=sprintf("%03d",c++)
>      $3=$3n
>      print c
>     }
>     1' "file"

Here's the reply from #awk at irc.freenode.net

[23:31] <karolisl> floyd_n_milan: awk '1' file
[23:31] <karolisl> try this one.
[23:31] <karolisl> it would work the same as cat.
[23:32] <floyd_n_milan> so what exactly does it do?
[23:33] <karolisl> floyd_n_milan: IMO, it works as : or true in shell
[23:33] <floyd_n_milan> hmmm
[23:34] <floyd_n_milan> same as print then?
[23:34] <karolisl> (in this case)
[23:34] <karolisl> floyd_n_milan: one can omit print
[23:34] <karolisl> awk '/foo/'
[23:34] <karolisl> awk '/foo/' file
[23:34] <karolisl> would work as a grep/.
[23:34] <floyd_n_milan> it does :
[23:34] <karolisl> because, if a pattern/an address/a condition is specified, 
awk defaults to print as an action for that block


-- 
----------------------------------------
Mrugesh Karnik
GPG Key 0xBA6F1DA8
Public key on http://wwwkeys.pgp.net
----------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://www.ae.iitm.ac.in/pipermail/ilugc/attachments/20071012/74b7a610/attachment.bin


More information about the ilugc mailing list