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.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-03-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
help with SED/AWK

Hi:
I have a file(ex: file1) containing strings like \$\$VAL1\$\$ value1 in each line.

Now I want to read all these strings from this file1 and replace the value of $$VAL1$$ with the "value1" in another file (ex: file2).

I tried something like:
------------------------------------------------------
#!/bin/ksh

VALUE1=`awk '/VAL1/ {print $2}' file1`
cat ./file2 | sed "s/\$\$VAL1\$\$/"$VALUE1"/" > ./temp
mv temp file2
------------------------------------------------------

but the "sed" part is not working as expected. plz help.
Reply With Quote
Forum Sponsor
  #2  
Old 05-04-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
it is working for normal case.

but in my case the string will be: $$VAL1$$ /home/xyzzz/

so while substituiting with sed, sed is confused as it has "/" character in the string.


I am getting the following error:
sed: command garbled: s/$$VAL1$$//home/xyzzz/

any help is appreciated.
Reply With Quote
  #3  
Old 05-04-2006
Registered User
 

Join Date: Jul 2005
Posts: 137
Code:
awk '
ARGV[1]==FILENAME && /VAL1/ { value = $2 }
ARGV[2]==FILENAME { sub( /\$\$VAL1\$\$/, value ); print }
' file1 file2
Reply With Quote
  #4  
Old 05-04-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
Quote:
Originally Posted by futurelet
Code:
awk '
ARGV[1]==FILENAME && /VAL1/ { value = $2 }
ARGV[2]==FILENAME { sub( /\$\$VAL1\$\$/, value ); print }
' file1 file2
Thanks for the reply.

I am getting the following error.

awk: syntax error near line 3
awk: illegal statement near line 3

any clues..?
Reply With Quote
  #5  
Old 05-04-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,014
as always..... if under Sun/Solaris, use 'nawk'' istead of 'awk'
Reply With Quote
  #6  
Old 05-04-2006
Registered User
 

Join Date: Jul 2005
Posts: 137
Even better perhaps, /usr/xpg4/bin/awk
Reply With Quote
  #7  
Old 05-08-2006
Registered User
 

Join Date: Apr 2006
Posts: 4
Thank You ALL for your help.
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 03:44 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