help on sed replacing special characters

Hello,

I have a file with many lines with below format:

\abc\\1234
jkl\\567
def\\345
\pqr\\567
\xyz\\234

Here, i need to do 2 things.

  1. replace \\ with \

  2. remove starting \

so output to be as below:

abc\1234
jkl\567
def\345
pqr\567
xyz\234

Thanks
Prvn

try this...

sed -e '{s/\\\\/\\/g;s/^\\//}' input.txt

sed 's \\\\ \\ ;s ^\\  ' filename

Hi radoulov, Your solution is excellent and worked great..Thanks

quintet, Thank you. Your solution throwing error below:
sed: command garbled: {s/\\\\/\\/g;s/^\\//}

Thanks much,
Prvn

quintet solution works once you take out "{" and "}" characters

sed -e 's/\\\\/\\/g' -e 's/^\\//' input.txt

sed 's?\\??' file

shamrock,

Have you test your solution?
This:

echo '\abc\\1234' | sed 's?\\??'

gives:

abc\\1234

Regards

Yes I tested it on an AIX machine and it gives the correct output. See below

$ echo '\abc\\1234' | sed 's?\\??'
bc1234

But the OP expect:

abc\1234

Read the first post.

Regards

You are right...sorry I didn't pay close attention to the posting :eek:

i have a variable lets say
a=/net/node/port.

i need to replace "/" with "\/" so output should be

\/net\/node\/port

The delimiter in sed doesn't have to be "/". In this example it is "A".

echo "/net/node/port"|sed -e "sA/A\\\\/Ag"

\/net\/node\/port