The specified optionally quoted file with channel separators with the following entries:
"foo"|"bar"|123|"9" Nails"|"2"
"blah"|"blah"|456|"Guns "N" Roses"|"7"
"brik"|"brak"|789|""BB" King"|"0"
"yin"|"yang"|789|"John "Cougar" Mellencamp"|"5"
I want to replace any double quotes next to the delimiter.
I used the following and it almost works. With one exception.
sed "s/\([^|]\)\"\([^|]\)/\1'\2/g" a.txt
The result is as follows:
"foo"|"bar"|123|"9' Nails"|"2"
"blah"|"blah"|456|"Guns 'N" Roses"|"7"
"brik"|"brak"|789|"'BB' King"|"0"
"yin"|"yang"|789|"John 'Cougar' Mellencamp"|"5"
It does not capture the second set of quotes if they are separated by a single character, as in Guns "N" Roses. Does anyone know why this is so and how it can be fixed? At the same time, I just pass the output to the second regular expression to handle the special case. I would prefer to do this in one go, as some files can be quite large.
Thanks in advance.
source
share