Answer the question
In order to leave comments, you need to log in
How to make awk or sed not split substrings with quoted spaces?
There is a file where strings can contain substrings delimited by double quotes.
These substrings can be either with or without spaces.
awk does not accept quotes and separates such substrings by spaces.
Example:
cat test.txt abc
"line1" where flick is "line 2" lmnop
bav "line 3" where flick is "line 4" lmnop
cat test.txt | awk '{print $1":"$3":"$4":"$6}'
abc:where:jzik:2" ab
:3":where:"string
to get:
abc:where:jzik:lmnop baw
:where: zhzik: lmnop
Please help.
Answer the question
In order to leave comments, you need to log in
Why not first remove the extra substrings and then substitute the required separator instead of spaces?
cat test.txt | sed -E 's/(["]+[a-zA-Za-zA-Z0-9 ]+["]+)//g; s/+/:/g'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question