Sed unknown option to s

Need help with C, C++, perl, python, etc?

Sed unknown option to s

Postby Lavendem » 2007-09-30 20:19

Hello!

I am making an automated script to install a certain Windows application via Wine. Because the application itself always runs in full screen mode which results in Wine crashing it needs to be run in a Virtual Desktop.. I'm trying to achieve that by seding the .desktop file... however I can't find the problem to why this won't work:
sed -i "s/env WINEPREFIX=\"$HOME\/.wine\" wine/env WINEPREFIX=\"$HOME\/.wine\" wine explorer \/desktop=\"Wine\",800x600/ $(\/usr\/local\/bin\/fconv --init \"$HOME\/FabiusConv\/\")" "$HOME/Desktop/FabiusConv.desktop"

Thanks in advance!
NOTE: The script should be portable and that's why I need to use a double-quote instead of a singe-quote to be able to use the $HOME variable and the $(\/usr\/local\/bin\/fconv --init \"$HOME\/FabiusConv\/\") command.

Thanks in advance!
Lavendem
 
Posts: 416
Joined: 2007-09-06 19:09

Postby jozyba » 2007-10-01 11:06

Firstly, you can avoid having to escape the forward slashes if you use a different delimiter:
Code: Select all
sed 's_/this/is/a/path_/this/is/the/replacement/path_'

Secondly, are you searching and replacing the literal string '$HOME' or its expanded form?
e.g. say that the file FabiusConv.desktop contains these two lines:
Code: Select all
env WINEPREFIX=$HOME/.wine wine
env WINEPREFIX=/home/freddy/.wine wine    # or whatever your user name is instead of 'freddy'

Then this will find and replace the first line:
Code: Select all
sed -i.bak 's_env WINEPREFIX=$HOME/.wine wine_env WINEPREFIX=$HOME/.wine wine explorer /desktop=Wine,800x600_' $HOME/Desktop/FabiusConv.desktop

And this will find and replace the second line - (just leave the $HOME variable outside the single-quotes so that the shell can expand it):
Code: Select all
sed -i.bak 's_env WINEPREFIX='$HOME'/.wine wine_env WINEPREFIX='$HOME'/.wine wine explorer /desktop=Wine,800x600_' $HOME/Desktop/FabiusConv.desktop

Thirdly, if you're not yet sure that a sed script is going to do what you want then it's a bad idea to use the edit-in-place '-i' option; even when you've perfected the script it's good to keep a backup with 'sed -i.bak ...'
jozyba
 
Posts: 76
Joined: 2007-08-23 18:08

Postby Lavendem » 2007-10-01 21:19

Thanks for the lesson!

Now I learned a lot more than what I would have from the sed man page :p
Lavendem
 
Posts: 416
Joined: 2007-09-06 19:09

Postby jozyba » 2007-10-02 01:12

Lavendem wrote:Now I learned a lot more than what I would have from the sed man page.

Yes, this is one of those situations where 'info sed' will tell you a *lot* more than 'man sed'.
jozyba
 
Posts: 76
Joined: 2007-08-23 18:08


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable