![]() |
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 |
| Search, replace string in file1 with string from (lookup table) file2? | gstuart | Shell Programming and Scripting | 9 | 06-08-2009 06:11 AM |
| search excat string in another string (grep "fails") | bora99 | UNIX for Dummies Questions & Answers | 0 | 06-05-2008 06:41 AM |
| search text string | itik | AIX | 2 | 01-28-2008 07:01 PM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 10:24 AM |
| appending string to text file based on search string | malaymaru | Shell Programming and Scripting | 1 | 06-09-2006 08:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Search a string and append text after the string
Hi,
I have a file like this... <o t="Batch" id="8410" p="/" g="32"> <a n="name"> <v s="DBBA1MM"/> </a> <a n="owner"> <v r="/[AdminUser]Administrator"/> </a> <a n="rights"> <v s="95"/> </a> <a n="debugLevel"> <v s="3"/> </a> <a n="avsStoreLoc"> <v s="/home/kp1771/fw_base_path/collectors/DBBA1MM/avs"/> </a> </o> <o t="Batch" id="8410" p="/" g="27"> <a n="name"> <v s="DBBA1MM"/> </a> <a n="owner"> <v r="/[AdminUser]Administrator"/> </a> <a n="rights"> <v s="95"/> </a> <a n="avsStoreLoc"> <v s="/home/kp1771/fw_base_path/collectors/DBBA1MM/avs"/> </a> </o> I have to add <a n="debugLevel"> <v s="3"/> </a> after <a n="rights"> <v s="95"/> </a> if <a n="debugLevel"> <v s="3"/> </a> does not exits. I have to add the tag in red If exists has to modify <a n="debugLevel"> <v s="4"/> </a> can you help me on this..any type of help is appriciated thanks |
|
||||
|
Have you tried anything so far? I would use awk to do this. When it finds <a n="rights"> you could read ahead a few lines using getline. If it contains "debugLevel" you could print out the new debug level, if not, just add debug level 3. For every other line, just print it.
|
|
||||
|
Here, I've done most of the work for you, you should be able to finish it easily:
Code:
awk '
/n="rights"/ {
print
getline ; print
getline ; print
getline
if (match($0,"debugLevel")) {
print "<a n=\"debugLevel\">\n<v s=\"4\"/>\n</a>"
# consume and discard next two lines
getline
getline
} else {
# do some stuff here
print
}
next
}
1 # print other lines
' inputfile > outputfile
|
|
||||
|
Code:
cp -p originalfile originalfile.bak && awk '<your script here>' originalfile.bak > originalfile |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|