Computing.Net > Forums > Unix > Replacing incremntal string in file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replacing incremntal string in file

Reply to Message Icon

Name: samarjith
Date: January 8, 2009 at 10:38:06 Pacific
OS: Windows 2000
CPU/Ram: Intel(R) Pentium(R) M processor 2.00 GHz
Product: Ibm / T43
Subcategory: Software Problems
Comment:

we recieve a xml file daily....that has the following info.

<Image1 vt="9" clsid="{A503C21E}">
<ImageState vt="3">2</ImageState>
<ImageReason vt="3">0</ImageReason>
<ImageJobID vt="8">{F16034AD}</ImageJobID>
</Image1>
<Image2 vt="9" clsid="{A503C21E}">
<ImageState vt="3">3</ImageState>
<ImageReason vt="3">0</ImageReason>
<ImageJobID vt="8">{F16035AD}</ImageJobID>
</Image2>
<Image1 vt="9" clsid="{A503C21E}">
<ImageState vt="3">4</ImageState>
<ImageReason vt="3">0</ImageReason>
<ImageJobID vt="8">{F16036AD}</ImageJobID>
</Image1>

Now I want to replace the Image1,Image2,Image3 tags with Image. In the original file it can be any like Image1...Image10000. so I need to replace all the tags to Image. And there will be 5000 files every day to be processed like this. Can anybody help me in fixing this? Thanks in advance.

Samar



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: January 8, 2009 at 11:16:43 Pacific
Reply:

Here is the hard part, replacing the tags:

sed -e 's/^<Image[0-9]*/<Image/' -e 's/^<\/Image[0-9]*/<\/Image/' myfile.xml


0

Response Number 2
Name: samarjith
Date: January 8, 2009 at 13:04:36 Pacific
Reply:

above solution is working if the xml file is indented. My files are not indented....from first to last they are on one line. I tried the above solutions on unindented files, but it is not working. Please provide me the solution for an unindented file.


Thanks

Samar


0

Response Number 3
Name: nails
Date: January 8, 2009 at 21:11:21 Pacific
Reply:



sed -e 's/<Image[0-9]*/<Image/g' -e 's/<\/Image[0-9]*/<\/Image/g' myfile.txt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Comunicattion between pro... is there a wild card for ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Replacing incremntal string in file

Replace a string in Script www.computing.net/answers/unix/replace-a-string-in-script/7047.html

Find and Change String in File www.computing.net/answers/unix/find-and-change-string-in-file/4628.html

Search and replace string in files www.computing.net/answers/unix/search-and-replace-string-in-files/7857.html