LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Transform \\psds0t01\c$ to psds0t01_c (https://www.linuxquestions.org/questions/programming-9/transform-%5C%5Cpsds0t01%5Cc%24-to-psds0t01_c-473010/)

lecontel 08-11-2006 11:27 AM

Transform \\psds0t01\c$ to psds0t01_c
 
Hello,

I want to transform in a file a string in form
\\[a-z]|[A-Z]|[0-9]\[a|z]$

For example:
\\psds0t01\c$ to psds0t01_c
\\CCR478e0\z$ to CCR478e0_z

I try :

extract the string in a variable and use tr
but \c cause probleme, but \d is good

use sed directly from the file gives same bad result

Thank you for help

druuna 08-11-2006 11:48 AM

Hi,

Using sed:

sed -e 's/^[\]*//' -e 's/\$$//' -e 's/\\/_/' infile

infile contains:

\\psds0t01\c$
psds0t01_c
\\CCR478e0\z$
CCR478e0_z

Test run:

$ sed -e 's/^[\]*//' -e 's/\$$//' -e 's/\\/_/' infile
psds0t01_c
psds0t01_c
CCR478e0_z
CCR478e0_z

Hope this helps.

AnanthaP 08-11-2006 11:49 AM

s/^\\// - If the first chzracte is a backslash, then convert it to nothing.
s/\\/\_/ - If a back slash, then substitute it with an underscore.
s/$\$// - If the last characte is a $, then then convert it to nothing.


All times are GMT -5. The time now is 04:09 PM.