Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: heredoc in ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 2228 of 2241
Post > Topic >>

Re: heredoc in awk? avoid nasty quoting to print o/p with special

by Janis Papanagnou <Janis_Papanagnou@[EMAIL PROTECTED] > May 2, 2008 at 08:14 PM

Rahul wrote:
> Is there something akin to a "heredoc" in awk? I need to process a set
of 
> records, extract relevant numbers from each record and then create a 
> formatted multi-line output for each record. Problem is that the output 
> would contain a lot of special characters and using a normal print or 
> printf would need me to do some nasty quoting (or not?)

The only characters I can think of that need "special quoting" are the
double quotes and the backslash escape character. Though you can use
variables to get the quotes quite legible. See the example...

   BEGIN { Q = "\"" }
   {
     print Q "id" Q ":" Q "town"
     print Q  $1  Q ":" Q  $2
   }


Janis

> 
> The desired output snippet for each record is something like this:
> 
>   {"id":"town",
>    "label":"middleton",
>    "x_size":"10.22",
>    "y_size":"5.22",
>   },
> 
> 
> Of course, I'd be using $1 (or equivalent variables) for the town, 
> middleton, 10.22, 5.22 etc. 
> 
> Any constructs like the familiar bash
> 
> print << EOF
> static blah blah
> "${var_to_be_inserted}"
> more static blah blah
> EOF
>




 4 Posts in Topic:
heredoc in awk? avoid nasty quoting to print o/p with special ch
Rahul <nospam@[EMAIL P  2008-05-02 17:52:21 
Re: heredoc in awk? avoid nasty quoting to print o/p with specia
Janis Papanagnou <Jani  2008-05-02 20:14:25 
Re: heredoc in awk? avoid nasty quoting to print o/p with specia
Ed Morton <morton@[EMA  2008-05-02 15:43:45 
Re: heredoc in awk? avoid nasty quoting to print o/p with specia
gazelle@[EMAIL PROTECTED]  2008-05-02 22:41:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 8:48:14 CDT 2008.