I'm trying to change the text in a file from this:
file.txt,c:\path\to\file
file.txt,c:\path with spaces\to\file
file.txt,c:\path\to\file with spaces
file.txt,c:\path\to\file with spaces
file.txt,c:\path\to\file with spaces
To this kind of output (one path to the file):
c:\path\to\file\file.txt
c:\path with spaces\to\file\file.txt
c:\path\to\file with spaces\file.txt
c:\path\to\file with spaces\file.txt
c:\path\to\file with spaces\file.txt
This ALMOST works but requires a ',' on the end of the line :
sed 's@\(.*\),\(.*\),\(.*\)@\2,\1,\3@g' file
Any help would be appreciated, I don't know sed all that well...
EDIT
This worked for me but I would still like to add a "\" in there:
sed 's@\(.*\),\(.*\)@\2,\1,\3@g' file
Escape the backslash, \\
.
sed 's/^\(.*\),\(.*\)$/\2\\\1/g' file
--^^--
Also, you only need two capturing groups.
But since I'm more an awk
guy.
awk -F, '{ print $2 "\\" $1 }' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With