- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Chaning a string using sed giving parse error
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 02:46 AM
01-24-2003 02:46 AM
Chaning a string using sed giving parse error
I'm trying to chg a string in a file with another string within a loop, but am getting a parse error on the sed operation :
for e in `cat $hm/l1`
do
e0=`$hm/i1 $e`
sed -e 's/'$e'/'$e0'/g' $hm/dw > $hm/dw1
done
Error is
sed: Function s/030113/ Mon cannot be parsed.
sed: Function s/030114/ Tue cannot be parsed.
where file l1 contains
030113
030114
and job i1 returns a day
Any ideas - Appologies if it's something obvious
Enda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 03:17 AM
01-24-2003 03:17 AM
Re: Chaning a string using sed giving parse error
Try this instead:
$hm/i1 $e | read e0
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 03:28 AM
01-24-2003 03:28 AM
Re: Chaning a string using sed giving parse error
My first suggestion is to use double quotes to make the command more readable:
sed -e "s/$e/$e0/g" $hm/dw >$hm/dw1
to be more lenient to the pattern, use perl's alternate syntax for s///, that would catch this:
perl -pe "s{$e}{$e0}g" $hm/dw >$hm/dw1
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 03:29 AM
01-24-2003 03:29 AM
Re: Chaning a string using sed giving parse error
Or perhaps i1 returns '/' characters ... You can use any character as a separator instead of /. Try for example ';' :
sed -e 's;'$e';'$e0';g' $hm/dw > $hm/dw1
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 03:31 AM
01-24-2003 03:31 AM
Re: Chaning a string using sed giving parse error
thanks for that. This has lead me to another problem in that the second string 030114 converts ok but the first string 030113 doesn't convert at all...it's as if sed is ignoring the first loop(if I put in a grep to see if the correct strings are been used and are in the dw file everything looks ok)
Cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 07:30 AM
01-24-2003 07:30 AM
Re: Chaning a string using sed giving parse error
It looks like if $hm is set before the loop, then $hm/dw and $hm/dw1 will be the same value for each iteration of the loop.
Thus $hm/dw1 will have the last sed command run, which is your 030114. The 030113 is overwritten.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 07:48 AM
01-24-2003 07:48 AM
Re: Chaning a string using sed giving parse error
sed -f myfile $hm/dw > $hm/dw1
This would require building "myfile" with s/// commands from your $hm/l1 file.
If you used perl, then you could do something like
perl -en '$hm=ENV{"hm"};$x=`$hm/i1 $_`; print "s/$_/$x/g\n";}' $hm/l1 >myfile
to create "myfile".
But if you used perl, you could do it with using "sed".
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 08:38 AM
01-24-2003 08:38 AM
Re: Chaning a string using sed giving parse error
perl -en '$hm=ENV{hm};chomp($x=`$hm/i1 $_`); print "s/$_/$x/g\n";}' $hm/l1 >myfile
backticks are not (yet) autochomped
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2003 01:17 PM
01-24-2003 01:17 PM
Re: Chaning a string using sed giving parse error
-- Rod Hills