AWK is not able to split a line when seperator is |||

Viewed 55

Let's assume I have a file as follows (file.txt):

My name is John ||| Second part of example.

To get the first part (till |||)

I did the following:

awk -F '|||' '{print $1}' file.txt 

However, this command gives me the whole line.

How can I get the portion of each line until ||| ?

1 Answers

This should work:

awk -F"[|][|][|]" '{print $1}' file
My name is John

Second part

awk -F"[|][|][|]" '{print $2}' file
 Second part of example.

And as @glenn shows:

awk -F"[|]{3}" '{print $1}' file
My name is John
Related