Muddassir Rahman
Muddassir Rahman

Reputation: 956

Awk command to extract columns on dual delimiter

I have a file which contains rows like this

name[^legalName[^code[^type[^contactNumber1[^contactNumber2

I want to extract column two from this file. I don't find any problem when I have a single character delimiter. But how do I extract when there is a multiple character delimiter.

Upvotes: 2

Views: 103

Answers (1)

merlin2011
merlin2011

Reputation: 75565

awk interprets the field separator as a regular expression, so you just need to double \\ escape each character to get the literals.

echo 'name[^legalName[^code[^type[^contactNumber1[^contactNumber2' | awk -F'\\[\\^' '{print $2}'
legalName

Upvotes: 2

Related Questions