If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > programfile & flags/variables as a variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-03, 19:41
Douglas Anderso Douglas Anderso is offline
Registered User
 
Join Date: Jul 2003
Posts: 6
programfile & flags/variables as a variable

Ok I'm stuck....

I've got a variable called $DATA that basically contains:
NR==1 {print $0} NR==2 {print "inserted data" substr($0,96)}.....

What I want to do is use this as part of the awk 'command line'

ie: awk '$DATA' file_being_read.dat

No matter what I do I can't seem to make this work...Is it possible? I just want to string together the 'command line' for awk and run it...

Thanks,
Doug.
Reply With Quote
  #2 (permalink)  
Old 10-07-03, 04:30
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You'll need to use 'eval' to evaluate the line before passing it to the shell. You'll need to make some slight changes though to escape items in your awk string that don't want to be evaluated initially.


DATA="NR==1 {print \$0} NR==2 {print \"inserted data\" substr(\$0,96)}"

eval awk '$DATA' file_being_read.dat

I always use 'echo' to test the string that I will be evaluating (as this will itself evaluate the input before echoing it out)...

$ echo $DATA
$ NR==1 {print $0} NR==2 {print "inserted data" substr($0,96)}

Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On