logo       

Re: Unexpected replacement: msg#00058

editors.sed.user

Subject: Re: Unexpected replacement

Thanks, I'll try this tomorrow.

Greg


>From: hq00e <hq00e@xxxxxxx>
>To: gregh_oh <gregh_oh@xxxxxxxxxxx>
>CC: "sed-users.yahoogroups.com" <sed-users@xxxxxxxxxxxxxxx>
>Subject: Re: Unexpected replacement
>Date: Thu, 15 Dec 2005 00:29:08 +0800
>
>
>On Wed, 14 Dec 2005 21:59:11 +0800, gregh_oh wrote:
>
>>Good day sedders,
>>
>>I am trying to write a simple batch file to do some replacements
>>within an XML file using GNU sed version 4.0.7 on Windows XP.
>>
>>Here is the line (#62)I'm targeting:
>>
>><menutree:TREENODE TEXT="Updates" EXPANDED="true"
>>TREENODESRC="xmlfiles/Menu.xml" IMAGEURL="images/folder.gif"
>>EXPANDEDIMAGEURL="images/folderopen.gif" FILENAME=""/>
>>
>
>Judging from the result you give, the last 3 lines were actually
>one wrapped long line.
>
>>Here is the snipit from the batch file that invokes sed:
>>
>>SET /P Choice=Enter tree node text and press Enter:
>>sed 62s/TREENODE\x20TEXT.*EXPAND/TREENODE\x20TEXT\x3D\x22"%
>>Choice%"\x22\x20EXPAND/ <..\Incrementals.html > tmp.txt
>>
>
>3 hints:
>1st. '.*' pattern is greedy which means it will match a string as long as
>possible.
>2nd. Enclose your sed script with " on Windows, especially when there
>is environment varviable in it.
>3rd. Sed can either read input from stdin or files, so '<' in your script
>can be omitted.
>4th. There are metacharacters. Use them.
>
>>My expectation is that user input text from the variable %Choice%
>>replaces "Updates". However, given an input of: New Node Name, here
>>is what ends up in tmp.txt:
>>
>><menutree:TREENODE TEXT="New Node Name"
>EXPANDEDIMAGEURL="images/folderopen.gif" FILENAME=""/>
>>
>>Why is sed not stopping at the first occurence of EXPAND?
>>I'm sure that the answer is simple, but I just can't see it.
>>
>
>solution1. Change the portion of your script from:
>TEXT.*EXPAND
>to:
>TEXT=[^=]*EXPAND
>
>
>solution2. Use more metacharacters.
>sed -r "62s/(TREENODE TEXT=.)[^\x22]*/\1%Choice%/" ..\Incrementals.html
>
>
>--
>Regards,
>hq00e
>




------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~->

--

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/

<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/







<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise