The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Variables bobo UNIX for Dummies Questions & Answers 1 01-18-2007 10:37 PM
doing a sed on certain variables seaten UNIX for Dummies Questions & Answers 10 09-05-2005 07:45 PM
doing a sed with variables seaten Shell Programming and Scripting 1 05-06-2005 12:08 PM
doing a sed with variables seaten UNIX for Dummies Questions & Answers 1 05-06-2005 11:48 AM
Using Variables to Set Other Variables superdelic UNIX for Dummies Questions & Answers 3 04-21-2005 07:44 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-04-2005
Registered User
 

Join Date: Jul 2005
Posts: 9
Awk with variables

Hi

I have a file with a line like this, wich is read by an awk script :

Logical Name | Server Type | Server1 | DB1 | User1 | $PASSWORD | Serv2 |DB2 | User2 | $PASSWORD

Awk reads it fine, but...it doesnt interpret the variable $PASSWORD as I wish. How do I tell awk to substitute $PASSWORD by its value?

Thanks a lot
Reply With Quote
Forum Sponsor
  #2  
Old 08-04-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
... and what IS the value of '$PASSWORD'?
Reply With Quote
  #3  
Old 08-04-2005
Registered User
 

Join Date: Jul 2005
Posts: 9
This is the value:

echo $PASSWORD
martinsc

However, I dont want to use the value in the file. I need to use the variable $PASSWORD.

Thank you.
Reply With Quote
  #4  
Old 08-04-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
something along these lines.....

nawk -v var='PASSWORD' -v val='foo' -f scar.awk myFile.txt

scar.awk:
Code:
BEGIN {
  FS="|"
  PAT_var= "(^| )[$]" var "($| )"
}
{
   gsub(PAT_var, " " val " ")
   print
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0