![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Code:
awk '
ARGV[1]==FILENAME && /VAL1/ { value = $2 }
ARGV[2]==FILENAME { sub( /\$\$VAL1\$\$/, value ); print }
' file1 file2
|
|
#4
|
|||
|
|||
|
Quote:
I am getting the following error. awk: syntax error near line 3 awk: illegal statement near line 3 any clues..? |
|
#5
|
||||
|
||||
|
as always..... if under Sun/Solaris, use 'nawk'' istead of 'awk'
|
|
#6
|
|||
|
|||
|
Even better perhaps, /usr/xpg4/bin/awk
|
|
#7
|
|||
|
|||
|
Thank You ALL for your help.
|
|||
| Google The UNIX and Linux Forums |