Reputation: 307
I have a CSV file and want to only remove all quotes unless inside of a string.
Example:
"I have a file that says "need help" please"
I want to remove all double quotes in the text unless inside of double quotes. Example, don't remove the quotes around "need help"
Anyone have a clue?
I'm getting pretty good at awk
and sed
commands but this one stumped me.
Thanks for the help!
Upvotes: 0
Views: 1775
Reputation: 204731
This may or may not do what you want depending on your CSV format and requirements:
$ cat file
"I have a file that says "need help" please"
"a "b" c","d "e" f"
$
$ awk -F'","' -v OFS=, '{$1=$1;gsub(/^"|"$/,"")}1' file
I have a file that says "need help" please
a "b" c,d "e" f
Upvotes: 2
Reputation: 7969
Use grep -Po '".*?"'
:
echo 'this is a test "I need help" and "it has to be now"' | grep -Po '".*?"'
"I need help"
"it has to be now"
Upvotes: 0