Jump to content

sed problems


Recommended Posts

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...?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 :thumbs:

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...