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 > awking the contents of a variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-28-03, 19:01
rev6 rev6 is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Question awking the contents of a variable

hi-
pardon my noobieness...
i'm having some trouble with the syntax for awking the contents of of a variable in a script.

i have a variable (let's say $foo) whose contents is:

one two three

how can i assign a new variable ($bar) the value of "three"?

by comparison, if the variable were instead a file named "foo" with the same contents, then

awk '/one/{print $3}' foo

gives me:

three

so again, how do i make awk look at the contents of a script variable rather than a file?

-thanks!
-rev6
Reply With Quote
  #2 (permalink)  
Old 09-29-03, 04:37
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You can pipe the string into awk using echo...

echo $foo | awk '/one/{print $3}'

or, have awk take its input directly from your variable...

awk '/one/{print $3}' << !!
$foo
!!

Is this what you mean?
Reply With Quote
  #3 (permalink)  
Old 09-29-03, 14:54
rev6 rev6 is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Thumbs up thanks!

thanks- this did the job nicely.
-rev6



Quote:
Originally posted by Damian Ibbotson
You can pipe the string into awk using echo...

echo $foo | awk '/one/{print $3}'

or, have awk take its input directly from your variable...

awk '/one/{print $3}' << !!
$foo
!!

Is this what you mean?
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