Can I use a field separator consisting of multiple characters? Like I want to separate words which contain quotes and commas between them viz.
"School","College","City"
So here I want to set my FS to be ",". But I am getting funny results when I define my FS like that. Here's a snippet of my code.
awk -F\",\" '
{
for(i=1;i<=NF;i++)
{
if($i~"[a-z0-9],[a-z0-9]")
print $i
}
}' OFS=\",\" $*
As you can see, you can combine more than one delimiter in the AWK field separator to get specific information.
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.
The default field delimiter or field separator (FS) is [ \t]+ , i.e. one or more space and tab characters.
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.
yes, FS could be multi-characters. see the below test with your example:
kent$ echo '"School","College","City"'|awk -F'","|^"|"$' '{for(i=1;i<=NF;i++){if($i)print $i}}'
School
College
City
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With