![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing a variable inside a variable to a function | KingVikram | UNIX for Dummies Questions & Answers | 2 | 01-14-2008 08:28 PM |
| Using variable inside 'sed' | Rock | Shell Programming and Scripting | 3 | 11-23-2007 04:50 PM |
| How to replace variable inside the variable | mani_um | Shell Programming and Scripting | 31 | 08-09-2007 11:56 PM |
| variable inside awk '{print $c}' | Tártaro | Shell Programming and Scripting | 3 | 04-13-2007 09:22 AM |
| ksh: A part of variable A's name is inside of variable B, how to update A? | pa3be | Shell Programming and Scripting | 4 | 03-30-2005 12:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
getting variable inside awk
Hi All,
I have awk script for replacing the nth ocurance of a string in an xml file... My code is like this FILETYPE=xml TAGNAME=type OCCURANCE=$1 TAGVALUE=valueur echo OCCURANCE:$OCCURANCE echo TAGNAME:$TAGNAME echo TAGVALUE:$TAGVALUE awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/< type(.+)type>/&&n==++c{sub("<type>(.+)</type>",s)}1' application.xml this is working correctly .. but if ia m replacing the <type tag with $TAGNAME inside singlequotes, its not working... awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/<$TAGNAME(.+)$TAGNAME>/&&n==++c{sub("<$TAGNAME>(.+)</$TAGNAME>",s)}1' application.xml How do we use a variable in the awk command? Thanks in advance |
|
||||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|