Visit Our UNIX and Linux User Community


Want to use sed to add some parameters at the end of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to use sed to add some parameters at the end of the line
# 1  
Old 10-23-2009
Want to use sed to add some parameters at the end of the line

Hello All,

I have a doubt in sed, i want to add some parameter at the end of the tag inside a xml tag. how to i do that. so i want to add Results="true" value="high" inside the xml tag.

Orignal
<execute description="reboot">
<execute description="Stop Servlet">

After adding the parameters:-
<execute description="reboot" Results="true" value="high">
<execute description="Stop Servlet" Results="true" value="high">

How do i do that.

Thanks
Adsi

Last edited by asirohi; 10-23-2009 at 06:39 PM..
# 2  
Old 10-23-2009
Code:
sed 's/>/ Results="true" value="high">/'

# 3  
Old 10-23-2009
This does not changes the things inside the xml file permanently. It just print the changes in the Command line. What changes should i make.I am enclosing my script below, when i pass the xml file to be modified from the command line.

Code:
#!/bin/sh

usage() {
 $ECHO "Usage: [not perfect]"
}

if [ $# -eq 0 ]; then
  usage
  exit 0
fi

cat $1 | grep "execute description=" |  sed 's/>/ Results="true" value="h
igh">/'



if [ $# -ne 1 ];
 then
 usage
 exit 1
 fi

# 4  
Old 10-23-2009
Quote:
Originally Posted by asirohi
This does not changes the things inside the xml file permanently. It just print the changes in the Command line. What changes should i make.I am enclosing my script below, when i pass the xml file to be modified from the command line.

Code:
#!/bin/sh

usage() {
 $ECHO "Usage: [not perfect]"
}

if [ $# -eq 0 ]; then
  usage
  exit 0
fi

cat $1 | grep "execute description=" |  sed 's/>/ Results="true" value="high">/'


UUOC.

Redirect the output to a file:

Code:
grep "execute description=" "$1" | sed 's/>/ Results="true" value="high">/' > newfile

# 5  
Old 10-23-2009
Oops, that was a dumb question, that worked but xml file now just has:-

<execute description="reboot" Results="true" value="high">
<execute description="Stop Servlet" Results="true" value="high">

where as it should be:-

<?xml version="1.0" encoding="UTF-8"?>
<start>
<execute description="reboot" Results="true" value="high">
<execute description="Stop Servlet" Results="true" value="high">
</start>

How could i fix this?

Thanks
Adsi
# 6  
Old 10-23-2009
Quote:
Originally Posted by asirohi
Oops, that was a dumb question, that worked but xml file now just has:-

<execute description="reboot" Results="true" value="high">
<execute description="Stop Servlet" Results="true" value="high">

where as it should be:-

<?xml version="1.0" encoding="UTF-8"?>
<start>
<execute description="reboot" Results="true" value="high">
<execute description="Stop Servlet" Results="true" value="high">
</start>

Why should it be? You used grep, which will only print the matching lines.

Code:
sed '/^<execute/ s/>/ Results="true" value="high">/' "$1" > newfile


Previous Thread | Next Thread
Test Your Knowledge in Computers #431
Difficulty: Medium
JavaScript arrow functions were first introduced in 6th Edition - ECMAScript 2015.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add a line to the end of a set of files without using sed command?

I understand that the SED command reads all the lines in the file before adding a required line to the end of the file. Is there another command that adds a line to the end of files without reading the entire file.... SED is increasing the processing time as the number of lines in each of the... (1 Reply)
Discussion started by: Kanch
1 Replies

2. UNIX for Dummies Questions & Answers

sed - Add a variable line to the end of a block beginning with a regex

Hi, Need some help with sed. I have a file that has sections : e.g. a=blah b=blah d=blah e=blah There's many sections in the file. (1 Reply)
Discussion started by: andyatit
1 Replies

3. Shell Programming and Scripting

sed removing until end of line

All: Can somebody help me out with a sed command, which removes the the first occurance of ')' until the end of the line If I have the following input ... (5 Replies)
Discussion started by: BeefStu
5 Replies

4. UNIX for Dummies Questions & Answers

Removing end of line using SED

Hello Friends, How can I remove the last two values of this line using sed John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638:9/3/90:45900 The result should look like this: John Carey:507-699-5368:29 Albert way, Edmonton, AL 25638 (3 Replies)
Discussion started by: humkhn
3 Replies

5. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

6. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

7. Shell Programming and Scripting

sed issue with end of line

Example, Trying to replace text to the end of a line. Text file looks like this PP= 4 PP= 412 PP= 425 I want to replace only the following line: PP= 4 with PP= 2 How can this be done with sed? (3 Replies)
Discussion started by: hanson397
3 Replies

8. Shell Programming and Scripting

Add white space to the end of a line with sed

Im trying to add 5 blank spaces to the end of each line in a file in a sed script. I can figure out who o put the spaces pretty much anywhere else but at the end. thanks Karl (7 Replies)
Discussion started by: karlanderson
7 Replies

9. Shell Programming and Scripting

delete to end of line with SED

I have a file with a bunch of similar lines in which I want to extract a phrase delimited by the first occurance of a '>' at the beginning and the first occurance of a '<' at the end (you might have guessed these are beginning/end of HTML tags). Using Sed I have managed to delete up to and... (7 Replies)
Discussion started by: coldcanuck
7 Replies

10. UNIX for Dummies Questions & Answers

sed to end of line

I know this is going to be an easy anwer, but I haven't been able to figure this out - even with the help of the previous posts. I want to go from this PROD USER anon; to this TEST; I have coded a few sed commands, and none of them are getting the job done. anon will not always be the... (2 Replies)
Discussion started by: djschmitt
2 Replies

Featured Tech Videos