I know this question is already answered but with comma as a separator. How to make awk ignore the field delimiter inside double quotes?
But My file is separated by pipe, when I use this in regex it act as a regex only and not getting proper output. I do not use awk extensively.. my requirement is add single slash before pipe character if it is coming in value.
As file size is almost 5GB, thought to select particular column and escaped the pipe.
INPUT:
"first | last | name" |" steve | white | black"| exp | 12
school |" home | school "| year | 2016
company |" private ltd "| joining | 2019
Expected Output:
"first \| last \| name" |" steve \| white \| black "| exp | 12
school |" home \| school "| year | 2016
company |" private ltd "| joining | 2019
I tried to use gawk with gsub but no luck.. is there any alternate approach for the same?
Also if I have to check in multiple columns how I can do that?
Assumptions:
|character (said field will be wrapped in double quotes)|character in a single fieldSetup:
NOTE: comments added here to highlight new cases
One
awkidea:This generates:
Assuming no spaces between the
|delimiter and double quotes ...One
GNU awkidea (using theFPATfeature):This also generates: