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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
11-07-2006, 11:52 PM
#1
LQ Newbie
Registered: Nov 2006
Posts: 8
Rep:
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
11-08-2006, 12:31 AM
#2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
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
11-08-2006, 12:41 AM
#3
LQ Newbie
Registered: Nov 2006
Posts: 8
Original Poster
Rep:
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"
11-08-2006, 12:43 AM
#4
LQ Newbie
Registered: Nov 2006
Posts: 8
Original Poster
Rep:
example
i m running
#!/bin/sh
sed 's/<Policyspace Name="File"/<Policyspace>/' filename.xml > filename2.xml
mv filename2.xml filename.xml
11-08-2006, 01:07 AM
#5
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545
Rep:
Here's a quick hint. Change your sed call to use the -i argument:
Code:
sed '/some/pattern/here/' -i filename.xml
11-08-2006, 01:11 AM
#6
LQ Veteran
Registered: Sep 2003
Posts: 10,532
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??
11-08-2006, 01:24 AM
#7
LQ Newbie
Registered: Nov 2006
Posts: 8
Original Poster
Rep:
<?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,
11-08-2006, 01:39 AM
#8
LQ Veteran
Registered: Sep 2003
Posts: 10,532
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!
11-08-2006, 07:23 AM
#9
Moderator
Registered: May 2001
Posts: 29,415
Yeah, using different separator should work and saves the necessity to escape stuff.
11-08-2006, 09:23 AM
#10
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
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
All times are GMT -5. The time now is 11:58 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News