The problem statement, all variables and given/known data:
Hi,
I am trying to substitute an attributes value using sed command but it is only possible to substitute the value without space.
Relevant commands, code, scripts, algorithms:
input xml
<BillingAddress11300000 Tag="11300000" SectionID="BLA" CustAddrName="CLAUDIA LUCIA DE ALMEIDA" CustAddrStreet="AV ENGENHEIRO RICHARD" CustAddrState="RJ" CustAddrZip="20561-090" CustAddrStreetNo="64" CustAddrComplement="APTO 303" CustAddrCity="RIO DE JANEIRO" CustAddrCounty="GRAJAU"/>
it will read the attribute and value will store it in variable
required output
<BillingAddress11300000 Tag="11300000" SectionID="BLA" CustAddrName="Rodrigo DE Silva" CustAddrStreet="AV ENGENHEIRO RICHARD" CustAddrState="RJ" CustAddrZip="20561-090" CustAddrStreetNo="64" CustAddrComplement="APTO 303" CustAddrCity="RIO DE JANEIRO" CustAddrCounty="GRAJAU"/>
The attempts at a solution (include all code and scripts):
I used the following script
#!/bin/bash
echo "Enter the attribute name"
read att
echo "enter new value"
read value
sed "s|$att\=\S*\S|$att=\"$value\"|g" test.xml>>out.xml
It is possible to substitute the attribute's value with this code with no space but it is not possible the f value substitution (The one with the space) with this script
How to implement this scenario?
#
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course)
School Name:Jalpaiguri Govt Engg College
Professor:Swapan kr Sengupta
Course Number:CSE502
Hi Sir,
I have almost tried it 50 times today with no hope.
it is possible to change "old" to "new" with my code. but it is not possibe to change "old value" to "new value" with this code.
it will be great if you could help with some code.
Thanks/
To expand on what RudiC said; I can assure you that "\S" in a search pattern in sed means different things to different versions of the sed utility. What operating system are you using? (If you don't know, what is the output from the command: uname -a ?) On your operating system, what is the full pathname of the sed utility you are using? (If you don't know, what is the output from the command: type sed ?)
What does the sequence \S match with the version of sed that you are using?
Step back and explain what you are hoping to match with the pattern $att\=\S*\S when you have attribute value pairs in your sample input like:
If you feed your current script the input CustAddrState in response to the request: Enter the attribute name and New State in response to the request: enter new value , what output does your current script add to the end of your output file? Did "RJ" change to "New State"? Did it really produce the output you wanted?
Actually it is NOT possible with your code and i tried to show you why using a simple example (instead of the complex you brought with you - we will come back to it once you can solve simple tasks).
So, again: suppose you have file containing only one this one line:
Attribute="old"
How would a sed-script look like to change "old" to "new"? Post the script and we proceed to the next step.
One thing which is not going to happen here is we provide the code to do it. My colleagues might have different takes about how to explain to you what you did wrong, but in this regard we all agree. Nobody here will write you a script (or part of a script) to do your homework for you. Instead we will try to help you do it yourself.