The input file i am testing with has just one line in it:
<int>163</int>\n <int>30</int>
This xml fragment is actually part of a web request recorded by a load testing tool. Since there are several places within the web request that numbers can occur, it is important to identify the surrounding tags <int> and </int> when matching pattern.
I did not understand your command but modified it slightly to remove the reference to 163:
sed '/[0-9][0-9]*/N;s:>[0-9][0-9]*<:>{requestId}<:2'
This returned an error:
c:>sed -f r.sed r.txt
sed: file r2.sed line 1: unknown option to 's'
I am testing this on windows with sedforwindows utility.
What does "N;s:>" , "<:>" parts and "<:2" of your command mean ?
Thanks.
---------- Post updated at 05:23 PM ---------- Previous update was at 04:28 PM ----------
A correction:
The input file (r.txt) i am testing with has just one line in it:
<int>163</int>\n <int>30</int>
This xml fragment is actually part of a web request recorded by a load testing tool. Since there are several places within the web request that numbers can occur, it is important to identify the surrounding tags <int> and </int> when matching pattern.
The numbers can be different each time the request is recorded.
I did not understand your command completely but modified it slightly to remove the reference to 163:
sed '/[0-9][0-9]*/N;s:>[0-9][0-9]*<:>{requestId}<:2'
This returned an error:
c:>sed -f r.sed r.txt
sed: file r.sed line 1: unknown option to 's'
I am testing this on windows with sedforwindows utility.
What does "N;s:>" , "<:>" parts and "<:2" of your command mean ?
Thanks.
---------- Post updated 01-08-11 at 12:35 PM ---------- Previous update was 01-07-11 at 05:23 PM ----------
Here is a rough sample of an input web request :
web_request(abc,
"Method=null",
"TargetObjectId=/1",
BEGIN_ARGUMENTS,
"<timestamp>0</timestamp>\n <timeToLive>0</timeToLive>\n <headers>\n "
" <entry>\n <string>DDD</string>\n <string>"
"</string>\n </entry>\n <entry>\n <string>asnumber</string>\n "
" <string>345</string>\n </entry"
">\n <entry>\n <string>bsnumber</string>\n <string>378"
"</string>\n </entry>\n </headers>\n <operation>handleCall</"
"operation>\n <parameters>\n <int>163</int>\n <int>30</int>\n "
" <string>CANCEL</string>\n <null/>\n <boolean>false</boolean>"
"\n </parameters>\n"
END_ARGUMENTS,
LAST);
I am interested in replacing the pattern <int>163</int>\n <int>30</int> within this web request.
Note the numbers between the tags <int> and </int> can be anything. Also there are several places where numbers occur in this web request.
I tried the following sed command and it worked only if I removed the newline and the multiple spaces (there can be any number of them) between the two repeating patterns <int>number</int>.
/web_request\(abc\)/,/^LAST/{
s/<int>\([0-9][0-9]*\)<\/int><int>\([0-9][0-9]*\)<\/int>/<int>\1<\/int><int>\{rid\}<\/int>/
}
For this sed command to work I had to alter the input web request to:
web_request(abc,
"Method=null",
"TargetObjectId=/1",
BEGIN_ARGUMENTS,
"<timestamp>0</timestamp>\n <timeToLive>0</timeToLive>\n <headers>\n "
" <entry>\n <string>DDD</string>\n <string>"
"</string>\n </entry>\n <entry>\n <string>asnumber</string>\n "
" <string>345</string>\n </entry"
">\n <entry>\n <string>bsnumber</string>\n <string>378"
"</string>\n </entry>\n </headers>\n <operation>handleCall</"
"operation>\n <parameters>\n <int>163</int><int>30</int>\n "
" <string>CANCEL</string>\n <null/>\n <boolean>false</boolean>"
"\n </parameters>\n"
END_ARGUMENTS,
LAST);
}
I want to retain the newlines and the spaces(however many of them) occurring between the two repeating elements. How can I alter my sed command to achieve this ?
Desired output:
web_request("abc",
"Method=null",
"TargetObjectId=/1",
BEGIN_ARGUMENTS,
"<timestamp>0</timestamp>\n <timeToLive>0</timeToLive>\n <headers>\n "
" <entry>\n <string>DDD</string>\n <string>"
"</string>\n </entry>\n <entry>\n <string>asnumber</string>\n "
" <string>345</string>\n </entry"
">\n <entry>\n <string>bsnumber</string>\n <string>378"
"</string>\n </entry>\n </headers>\n <operation>handleCall</"
"operation>\n <parameters>\n <int>163</int>\n <int>{rid}</int>\n "
" <string>CANCEL</string>\n <null/>\n <boolean>false</boolean>"
"\n </parameters>\n"
END_ARGUMENTS,
LAST);
Thanks.