phunni Posted July 14, 2006 Report Share Posted July 14, 2006 I'm trying to run the following line in a bash script: sed -n s/localhost:1433/164.11.132.104:1433/g myuwe/apps/uPortal/properties/PersonDirs.xml My understanding is that ant instances of the string "localhost:1433" should be replaced by "164.11.132.104:1433", but this doesn't seem to be happening... What am I getting wrong...? Quote Link to comment Share on other sites More sharing options...
neddie Posted July 14, 2006 Report Share Posted July 14, 2006 Try sed -i -e "s/localhost:1433/164.11.132.104:1433/g" myuwe/apps/uPortal/properties/PersonDirs.xml -i means write the modified file back to where it was (in-place), and -e means that the following parameter is the expression to use (rather than reading a script from a file). Quote Link to comment Share on other sites More sharing options...
phunni Posted July 14, 2006 Author Report Share Posted July 14, 2006 Thanks neddie - you're my bash guru! Quote Link to comment Share on other sites More sharing options...
neddie Posted July 14, 2006 Report Share Posted July 14, 2006 Quote Link to comment Share on other sites More sharing options...
phunni Posted July 17, 2006 Author Report Share Posted July 17, 2006 It would appear that -i is not an argument all versions of sed will accept. It works quite happily in cygwin for example, but not on solaris where only -n -e and -f are supported Can anyone come up with a simple alternative? Quote Link to comment Share on other sites More sharing options...
neddie Posted July 17, 2006 Report Share Posted July 17, 2006 Best I can suggest is sed -e "s/whatever/something else/g" file1 > file2 this will pipe the output to a new file. For some reason it doesn't like piping back to the same file it's trying to read from. But you can check the second file and then copy it back over the first one :) Quote Link to comment Share on other sites More sharing options...
phunni Posted July 18, 2006 Author Report Share Posted July 18, 2006 That's proving hard to get working in a script for some reason... Is there a better option for find/replace than sed? The arse of it is that sed with a -i was perfect, but the soalris version doesn't have it... :sad: Quote Link to comment Share on other sites More sharing options...
phunni Posted July 18, 2006 Author Report Share Posted July 18, 2006 On the original sed command: sed -i -e "s/localhost:1433/164.11.132.104:1433/g" myuwe/apps/uPortal/properties/PersonDirs.xml I've made two very minor changes: perl-i -pe "s/localhost:1433/164.11.132.104:1433/g" myuwe/apps/uPortal/properties/PersonDirs.xml and it seems to be working a treat. I was trying to avoid perl because I was actually porting from a perl script and it did a whole bunch of complicated stuff... The fact, however, that I can use perl as a simple command - like sed (almost exactly like sed as it turns out...) means that it's still a bash script and I can understand and maintain it easily Quote Link to comment Share on other sites More sharing options...
neddie Posted July 18, 2006 Report Share Posted July 18, 2006 Interesting - never seen that before. Calling sed from a bash script works on the Sun box here, but your perl version works too and also works in-place so it's nicer. Quote Link to comment Share on other sites More sharing options...
phunni Posted July 18, 2006 Author Report Share Posted July 18, 2006 Out of interest - does the -i switch work on your Sun box for sed? Quote Link to comment Share on other sites More sharing options...
neddie Posted July 18, 2006 Report Share Posted July 18, 2006 No, it just says illegal option. No idea why, it works fine on Mandriva. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.