LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-07-2006, 11:52 PM   #1
bajaj111
LQ Newbie
 
Registered: Nov 2006
Posts: 8

Rep: Reputation: 0
running sed inside script file


when i m running sed commands on the shell directly they r working fine, but when i run them inside script file, its saying that the function cant be parsed
Kindly help
 
Old 11-08-2006, 12:31 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Could you give an example of what you are trying to do?

The following code snippet does work (not what you mean?):
Code:
#!/bin/bash

infile=$1

sed 's/THIS/THAT/g' $infile
 
Old 11-08-2006, 12:41 AM   #3
bajaj111
LQ Newbie
 
Registered: Nov 2006
Posts: 8

Original Poster
Rep: Reputation: 0
hi drunna

i am substituting some text inside an xml file, on the shell when i run sed it works fine, but when i run sed in script file, i think due to special characters in XML , it says the "function cant be parsed"
 
Old 11-08-2006, 12:43 AM   #4
bajaj111
LQ Newbie
 
Registered: Nov 2006
Posts: 8

Original Poster
Rep: Reputation: 0
example

i m running
#!/bin/sh
sed 's/<Policyspace Name="File"/<Policyspace>/' filename.xml > filename2.xml
mv filename2.xml filename.xml
 
Old 11-08-2006, 01:07 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Here's a quick hint. Change your sed call to use the -i argument:
Code:
sed '/some/pattern/here/' -i filename.xml
 
Old 11-08-2006, 01:11 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The example given by you works if I try it. Doesn't seem to be anything wrong with it:
Code:
$ cat filename.xml
Ubunto
/<Policyspace Name="File"/
Mandrake
After running your code snippet:
Code:
$ cat filename2.xml
Ubunto
/<Policyspace>/
Mandrake
Maybe your example does not reflect reality??
 
Old 11-08-2006, 01:24 AM   #7
bajaj111
LQ Newbie
 
Registered: Nov 2006
Posts: 8

Original Poster
Rep: Reputation: 0
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="pdosent.xsl"?>
<ENTITLEMENTS>
<HEADER>
<Version>6.0.0.3(060329a)</Version>
<Date>2006-10-14-09:58:59</Date>
<Server>10.16.12.97</Server>
<Domain>Default</Domain>
<Branches>server</Branches>
<User>sec_Default</User>
<Exclusion>0x00000000 0x00000000 0x00000000</Exclusion>
</HEADER>
<USER>
<Name>tam</Name>
<DN>cn=pdos user tamid,dc=bsnl,dc=in</DN>
<CN>tamid</CN>
<SN>tamid</SN>
<Desc></Desc>
<GSO>NO</GSO>
<Account>YES</Account>
<Password>NO</Password>
<Group>staf</Group>
<ToD>weekday:anytime:local</ToD>
</USER>
<USER_POLICY>
<Login>
<OBJ></OBJ>
</Login>
<Password>
<OBJ></OBJ>
</Password>
</USER_POLICY>
<Policyspace Name="File">
<OBJ>
<Name>/dev/kazndrv</Name>
<Perm>TR[OSSEAL]rw</Perm>
</OBJ>
<OBJ>
<Name>/dev/rmt0</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/home/ossadmn</Name>
<Perm>TR[OSSEAL]DKNRUdloprwx</Perm>
</OBJ>
<OBJ>
<Name>/home/ossadmn/dummy-passwd</Name>
<Perm>TR[OSSEAL]rw</Perm>
<Attribute>permit:group staff:rw:/usr/bin/vi</Attribute>
</OBJ>
<OBJ>
<Name>/opt/pdos</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdos_pwdrestrict</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdosaudview</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdosdestroy</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdoslpinf</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdoslpmd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdosrefresh</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdosshowmsg</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdossudo</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdostecd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/pdoswhoami</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/rc.lpm</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/rc.pdoslrd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/bin/rc.pdostecd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/etc</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/opt/pdos/etc/lpm.conf</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/etc/pdossudo.conf</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/etc/trace</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/opt/pdos/lib</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/opt/pdos/nls</Name>
<Perm>TR[OSSEAL]DKlrx</Perm>
</OBJ>
<OBJ>
<Name>/tmp/dummy-passwd</Name>
<Perm>TR[OSSEAL]rw</Perm>
<Attribute>permit:group staff:rw:/usr/bin/vi</Attribute>
</OBJ>
<OBJ>
<Name>/usr/bin/ps</Name>
<Perm>TR[OSSEAL]rx</Perm>
</OBJ>
<OBJ>
<Name>/usr/bin/telnet</Name>
<Perm>TR[OSSEAL]rx</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/audit</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/certs</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/cred</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/ffdc</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/hla</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/log</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/login</Name>
<Perm>TR[OSSEAL]Ndlorw</Perm>
<Attribute>permit:any-other:Ndlorw:/opt/pdos/bin/pdos_pwdrestrict /usr/bin/passwd /usr/bin/login /usr/sbin/login /usr/sbin/sshd /opt/ssh/sbin/sshd /usr/lib/ssh/sshd /opt/pdos/bin/pdoslpinf /usr/bin/su /bin/login /usr/local/sbin/sshd /usr/sbin/pure-ftpd /usr/sbin/in.rlogind /usr/sbin/vsftpd /usr/sbin/in.ftpd /usr/lbin/ftpd /usr/lbin/rexecd /usr/sbin/in.rexecd /opt/gnome/bin/gdm /usr/X11R6/bin/xdm /usr/bin/gdm-binary</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/lpm</Name>
<Perm>TR[OSSEAL]Ndlorw</Perm>
<Attribute>permit:any-other:Ndlorw:/opt/pdos/bin/pdos_pwdrestrict /usr/bin/passwd /usr/bin/login /usr/sbin/login /usr/sbin/sshd /opt/ssh/sbin/sshd /usr/lib/ssh/sshd /opt/pdos/bin/pdoslpinf /usr/bin/su /bin/login /usr/local/sbin/sshd /usr/sbin/pure-ftpd /usr/sbin/in.rlogind /usr/sbin/vsftpd /usr/sbin/in.ftpd /usr/lbin/ftpd /usr/lbin/rexecd /usr/sbin/in.rexecd /opt/gnome/bin/gdm /usr/X11R6/bin/xdm /usr/bin/gdm-binary</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/pdosbkup</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/pdoscfg</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/pdoslrd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/pdosteccfg</Name>
<Perm>TR[OSSEAL]r</Perm>
<Attribute>permit:any-other:r:/opt/pdos/bin/pdoswhoami</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/pdostecd</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/tcb</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/tec</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/tracelogs</Name>
<Perm>TR</Perm>
</OBJ>
<OBJ>
<Name>/var/pdos/umsg</Name>
<Perm>TR[OSSEAL]NRdlrw</Perm>
<Attribute>permit:any-other:NRdlrw:/opt/pdos/bin/pdosucfg /opt/pdos/bin/pdoscfg /opt/pdos/bin/pdosctl /opt/pdos/bin/pdoswhoami /opt/pdos/bin/pdoswhois /opt/pdos/bin/pdosshowuser /opt/pdos/bin/pdosrefresh /opt/pdos/bin/pdosdestroy /opt/pdos/bin/pdossudo /opt/pdos/bin/pdosobjsig /opt/pdos/bin/pdosd /opt/pdos/bin/pdoswdd /opt/pdos/bin/pdosauditd /opt/pdos/bin/pdoslpmd /opt/pdos/bin/pdoslrd /opt/pdos/bin/pdoslradm</Attribute>
</OBJ>
<OBJ>
<Name>/var/pdos/uuid</Name>
<Perm>TR</Perm>
</OBJ>
</Policyspace>
<Policyspace Name="NetIncoming">
</Policyspace>
<Policyspace Name="NetOutgoing">
</Policyspace>
<Policyspace Name="Surrogate">
<OBJ>
<Name>/User/ossadmn</Name>
<Perm>TR[OSSEAL]G</Perm>
<Attribute>permit:any-other:G:/opt/pdos/bin/pdossudo</Attribute>
</OBJ>
<OBJ>
<Name>/User/osseal</Name>
<Perm>TR[OSSEAL]G</Perm>
<Attribute>permit:any-other:G:/opt/pdos/bin/pdossudo</Attribute>
</OBJ>
</Policyspace>
<Policyspace Name="Sudo">
<OBJ>
<Name>/kill</Name>
<Attribute>
<Name>Sudo-Command</Name>
<Value>/usr/bin/kill</Value>
</Attribute>
<Attribute>
<Name>Sudo-Invoker-Password</Name>
<Value>"required"</Value>
</Attribute>
<Perm>TR[OSSEAL]x</Perm>
</OBJ>
<OBJ>
<Name>/passwd</Name>
<Attribute>
<Name>Sudo-Command</Name>
<Value>/usr/bin/passwd</Value>
</Attribute>
<Attribute>
<Name>Sudo-Invoker-Password</Name>
<Value>"required"</Value>
</Attribute>
<Perm>TR[OSSEAL]x</Perm>
</OBJ>
</Policyspace>

</ENTITLEMENTS>

In the xml code above i want to substitute <Policyspace Name="File"> with <Policyspace><OBJ><Policy>File</Policy></OBJ>

i have written the script as
#!/bin/sh
sed 's/<Policyspace Name="File">/<Policyspace><OBJ><Policy>File</Policy></OBJ> filename.xml

but its working on shell when i directly run the command but in side the script file it doesnt run
and i dont know from where this parsing problem is comin,
 
Old 11-08-2006, 01:39 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The problem must be caused by something else. Using the complete xml you posted (post #7) it works with the code you posted (post #4)

But........ the sed substitute part you posted last has forward slashes. Escape them or use a different separator for the substitute command. I.e:

sed 's/x/\/y/'
or
sed 's%x%/y%'

Please post relevant and correct information. Without it we are in the dark and you won't get a working solution!
 
Old 11-08-2006, 07:23 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Yeah, using different separator should work and saves the necessity to escape stuff.
 
Old 11-08-2006, 09:23 AM   #10
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by bajaj111
...
but its working on shell when i directly run the command but in side the script file it doesnt run
and i dont know from where this parsing problem is comin,
When you say it doesn't run, what do you mean? How are you invoking the script? Are there any error messages?

Can you also post the results of these commands:
Code:
echo $SHELL
ls -l /bin/sh
ls -l your_script_filename
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssimple shell script to parse a file ~sed or awk stevie_velvet Programming 7 07-14-2006 03:41 AM
Command interpretation issue in Sed script file angel115 Programming 9 04-21-2006 07:26 PM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM
Running FTP inside Shell Script truncates files jbhanc0125 Red Hat 3 01-16-2004 11:37 AM
Running a script file johnlb Linux - Newbie 2 02-19-2003 02:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration