Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use double quotes as field separator in AWK

Tags:

awk

How can I use double quotes as a field separator?

awk -v val=$num 'BEGIN { FS='"';}{}'

I am using above statement however encountered an error.

like image 766
Hrushikesh Avatar asked Aug 01 '13 04:08

Hrushikesh


People also ask

How do you mention field separator in awk?

Just put your desired field separator with the -F option in the AWK command and the column number you want to print segregated as per your mentioned field separator. Show activity on this post. AWK works as a text interpreter that goes linewise for the whole document and that goes fieldwise for each line.

What is field separator in awk?

The field separator, which is either a single character or a regular expression, controls the way awk splits an input record into fields. awk scans the input record for character sequences that match the separator; the fields themselves are the text between the matches.

How do I change the delimiter in awk?

AWK: Change Field Separator By default, awk uses both space and tab characters as the field separator. You can tell awk how fields are separated using the -F option on the command line.

What is awk default field separator?

The default field delimiter or field separator (FS) is [ \t]+ , i.e. one or more space and tab characters.


1 Answers

Two ways:

awk -v val=$num -F'"' '{}'

awk -v val=$num 'BEGIN { FS="\"";}{}'
like image 134
Kevin Avatar answered Oct 10 '22 18:10

Kevin