search and replace string having multiple special characters
below is extract of my file
$cat outgoing-xfer|grep destination-path
What I need is to replace "--destination-path=" with "--destination-path=/home/dest"
i.e. desired output is
I could achieve it with below command
$cat outgoing-xfer|grep destination-path|perl -pi -e "s/destination-path=/destination-path=\/home\/dest/g"
But the problem is that in this case i just wanted to append "/home/dest" for which I could easily escape "/" with just two "\", but I wonder if i have a long path like "/a/b/c/d/e/f/g/h/i/j" I will have to escape so many /. Is there any other way by which I can avoid escaping forward slash.
I tried following:
$cat outgoing-xfer|grep destination-path|perl -pi -e "s/destination-path=/'destination-path=\/home\/dest'/g"
but receiving follo error
Bareword found where operator expected at -e line 1, near "s/destination-path=/'destination-path=/home"
syntax error at -e line 1, near "s/destination-path=/'destination-path=/home"
Bad name after dest' at -e line 1.
tried with enclosing in double quotes as well but in vain :(
I don't know about perl, but in SED, you can use a different delimiter in the "s" command---this avoids having the "escape" the "/".
I don't understand the double-quotes with single quotes inside....
Note that you have to escape the escape ("\") to have it be read as a normal character.
it actually works for me
this isnt the problem, but do you need the extra grep command in there?? as the perl section is already searching for the string
That was such a quick reply!!
Both the solution worked! Many thanks mates..God bless you!
|All times are GMT -5. The time now is 11:16 AM.|