URGENT----shell script to change word in file
I want to replace a word in a particular file. I am attaching file here
Quote:
In the above file i want to change the number(1603 is not fixed and my not be fixed digits) to some other number in this line Quote:
Thanks in advance |
Code:
sed -i "s/<VR NM=\"EID\" VL=\"[0-9]*\"\/>/<VR NM=\"EID\" VL=\"2222\"\/>/" file.xml |
script to change the number
Quote:
Now i want to replace that number from cat command like cat id ==== displays 1883 number i tried like this Quote:
Quote:
|
The file epg_ren_event_id looks like a file created in DOS, hence the control character ^M which stats for the sequence \r\n (carriage return + newline). You have to convert it in unix format. E.g.
Code:
dos2unix epg_ren_event_id |
i want to remove all spaces from file content. i tried below one
Quote:
can anyone help me |
I agree it looks like a Dos file - if you have the fromdos utility andf want to do it in one you may do this :
Code:
sed -i "s/<VR NM=\"EID\" VL=\"[0-9]*\"\/>/<VR NM=\"EID\" VL=\"$(cat epg_ren_event_id | fromdos)\"\/>/" file.xml |
Quote:
Code:
sed -i "s/ //g" event_info.log |
thanks for reply.
i am having spaces after the number in my epg_ren_event_id file. I want to remove those spaces. then your script will work perfectly. i need a script to remove all spaces and tabs in a file content. please help me |
Quote:
Code:
cat epg_ren_event_id | tr -d ["\t "] > fixedfile.txt |
bgeddy is correct.
And *please* don't flag your topics as "urgent". OK? |
thanks a lot to all.
I resolved my problem |
Quote:
Now i am having so many lines like below with different values. Quote:
I mean on first occurrence i want to replace with 4444 and at second occurrence i want to replace with 5555 and so on. Please help me |
Well you certainly keep changing the goalposts on this one ! Have you tried anything to solve this ? I recommended you look into sed - this now looks more like an awk problem. There is an excellent tutorial book on both here.
On a broader note - there may be better ways of parsing XML files - python has excellent support for XML in its libraries. It may be worth looking into if you really want to get clever with this. Oh - and it goes without saying - I hope this isn't homework... You should experiment with solutions yourself to learn. |
I agree you should try a proper XML parser. Perl has several modules for that. Sounds like you want a general solution, so sed/awk are probably not the way to go.
|
thanks for reply.
XML files are fixed. i want to change the numbers automatically. that is my final goal. i am new to scripting. thats why i am going step by step. |
All times are GMT -5. The time now is 07:25 AM. |