extract substr of more than one fields

I have a file with lines like ab.cde..fghi.jk and want to extract the leading two parts, namely ab.cde for this example.

I tried

awk -F'.' '{print $1.$2}' file

but the dot is missing. And

awk -F'.' '{print $1\.$2}'

raises error.

>Solution :

Literal strings need double quotes around them.

awk -F'.' '{print $1"."$2}' file

Leave a Reply