prvnrk
1
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.
-
replace \\ with \
-
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
prvnrk
4
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
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
You are right...sorry I didn't pay close attention to the posting
i have a variable lets say
a=/net/node/port.
i need to replace "/" with "\/" so output should be
\/net\/node\/port
methyl
12
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