Attributes value substitution with sed command


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Attributes value substitution with sed command
# 8  
Old 08-12-2015
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course)

Quote:
School Name:Jalpaiguri Govt Engg College
Professor:Swapan kr Sengupta
Course Number:CSE502
City and Country are missing...
# 9  
Old 08-12-2015
Quote:
Originally Posted by RudiC
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course)


City and Country are missing...
School Name:Jalpaiguri Govt Engg College
Professor:Swapan kr Sengupta
Course Number:CSE502
City:Kolkata Country:India
# 10  
Old 08-12-2015
Quote:
Originally Posted by Bijayan Sarkar
I used the following script
Code:
#!/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

Well, your script is "almost good". Let us take a step back to analyse what is going wrong:

Suppose you have following input file (only one line):

Code:
Attribute="old"

How would you write a sed-script to change "old" to "new"?

I hope this helps.

bakunin
# 11  
Old 08-12-2015
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/
# 12  
Old 08-12-2015
Look at the \S*\S. This might match sth. that you don't intend to; you may want to replace those.

BTW, I'm not sure every sed version understands \S.
# 13  
Old 08-12-2015
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:
Code:
CustAddrStreet="AV ENGENHEIRO RICHARD" CustAddrState="RJ" CustAddrZip="20561-090"

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?
# 14  
Old 08-13-2015
Quote:
Originally Posted by Bijayan Sarkar
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.
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:

Code:
Attribute="old"

How would a sed-script look like to change "old" to "new"? Post the script and we proceed to the next step.

Quote:
Originally Posted by Bijayan Sarkar
it will be great if you could help with some code.
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.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Attributes value substitution with sed command

Hi, I am trying to substitute an attributes value using sed command but it is only possible to substitute the value without space. input xml <BillingAddress11300000 Tag="11300000" SectionID="BLA" CustAddrName="CLAUDIA LUCIA DE ALMEIDA" CustAddrStreet="AV ENGENHEIRO RICHARD" CustAddrState="RJ"... (3 Replies)
Discussion started by: Bijayan Sarkar
3 Replies

2. Shell Programming and Scripting

sed substitution

Hi everyone, I need very simple sed command to change a parameter in a text file. I have a line in this text which is like set xx 0.5 A program reads this file and does some algebraic calculations. So to make a parameter scan I need to change the value of xx. I thought I can do... (7 Replies)
Discussion started by: hayreter
7 Replies

3. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

4. AIX

Single command to change the attributes of all luns presented to an AIX host

Hi, I would like to know if there is a command similar to scsimgr in HP-UX that can help me change the algorithm and reserve_policy attributes of all luns presented to an AIX host. Otherwise I would have to use, chdev -l hdiskX -a algorithm=round_robin reserve_policy=no_reserve in a... (1 Reply)
Discussion started by: kanna_geekworkz
1 Replies

5. Shell Programming and Scripting

sed substitution

Hi I am trying to do a text insertion in a text file at a particular line number in a shell script. However its not working. sed '122i\ > for j in \`echo $MyList\` ; do perl -pi -e\'s#01\/01\/2009#01\/01\/2011#\' $j ; done' $HOME/MyScript.ksh The Actual line to be inserted at line 122... (5 Replies)
Discussion started by: som.nitk
5 Replies

6. Shell Programming and Scripting

Help with sed/substitution!

I have file.txt 1 4 7 9 3 I want to replace the tabs with a space, but my code doesn't work. cat file.txt | sed 's/"\t"/ /g' > t.txt But file is still the same. Numbers seperated by tabs instead of spaces. Help? (2 Replies)
Discussion started by: Bandit390
2 Replies

7. Shell Programming and Scripting

SED Substitution

Hi , I am stuck up in the below scenario:- I need to read a file name (eg A.txt) name frm another file (eg B.txt) and then I need to search for a particular expression in A.txt and substitute it with another expression. How can I use SED inside SHELL Scripting and command prompt as well to... (1 Reply)
Discussion started by: shubhranshu
1 Replies

8. Shell Programming and Scripting

Substitution using SED

Hi , I am stuck up in the below scenario:- I need to read a file name (eg A.txt) name frm another file (eg B.txt) and then I need to search for a particular expression in A.txt and substitute it with another expression. How can I use SED inside SHELL Scripting and command prompt as... (2 Replies)
Discussion started by: shubhranshu
2 Replies

9. UNIX for Dummies Questions & Answers

sed substitution

Hi, I have a set of files containing strings like I.TEST1_TEST2 or B.ESSA_ESSB for example. Does somebody know how to substitute these strings whith the same name and an extension "_V1" (ie. I.TEST1_TEST2_V1) using sed command or else ? (3 Replies)
Discussion started by: jo_aze
3 Replies

10. UNIX for Dummies Questions & Answers

Substitution using sed

I know we can substitute a string using sed but how? For example: sed 's/(old variable)/(new variable)/ details.dat Am I suppose to put $old variable or whatever? Because I tried many times, it didnt work by putting $old variable. Am I suppose to enclose it with "" or ''? Please help (3 Replies)
Discussion started by: Ohji
3 Replies
Login or Register to Ask a Question