The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to hide command line parameters? xyzt UNIX for Advanced & Expert Users 6 08-31-2009 07:31 PM
Reading putty command line parameters from Linux SFNYC UNIX for Advanced & Expert Users 1 04-15-2009 10:17 PM
How to use parameters in command line while submitting a report sreenusola UNIX for Dummies Questions & Answers 1 09-17-2008 02:48 PM
How do you take in variables/parameters from the command line? avisram UNIX for Dummies Questions & Answers 1 07-21-2005 09:47 AM
passing command line parameters to functions - sh vino Shell Programming and Scripting 5 03-05-2005 05:51 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
asirohi asirohi is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 56
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; 4 Weeks Ago at 04:39 PM..
  #2 (permalink)  
Old 4 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,352
Code:
sed 's/>/ Results="true" value="high">/'
  #3 (permalink)  
Old 4 Weeks Ago
asirohi asirohi is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 56
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 (permalink)  
Old 4 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,352
Quote:
Originally Posted by asirohi View Post
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 (permalink)  
Old 4 Weeks Ago
asirohi asirohi is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 56
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 (permalink)  
Old 4 Weeks Ago
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,352
Quote:
Originally Posted by asirohi View Post
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
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0