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 > AWK command in Unix

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-19-04, 15:25
sqlserver2k sqlserver2k is offline
Registered User
 
Join Date: May 2002
Location: Timbaktu
Posts: 185
AWK command in Unix

I want to capture the output of the AWK unix command to a variable, instead of it directing it to the terminal or writing to a file.
Is it possible?

My script looks like:
servername=$1
username=$2
awk -F":" -v srvname=$servername -v usrname=$username -v pass=$p '$1~srvname && $4~usrname {print $5} ' inputfilename

I want to capture print $5 to a variable?
Reply With Quote
  #2 (permalink)  
Old 03-19-04, 16:17
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The mecanism is the same for all commands :
variable=`command`

or variable=$(command) with bash/ksh

In your case :
Code:
servername=$1
username=$2
result=$(awk -F":" -v srvname=$servername -v usrname=$username -v pass=$p '$1~srvname && $4~usrname {print $5} ' inputfilename)
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-20-04, 13:03
sqlserver2k sqlserver2k is offline
Registered User
 
Join Date: May 2002
Location: Timbaktu
Posts: 185
Thanks!
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