arshaq
arshaq

Reputation: 11

Using double quotes with MATCHES in Pig

I am trying to filter my input in pig based on a string pattern which has double quotes in it.

For example, say the input.txt has

field1="value1" field2="value2"
field1="value1" field2="val2"

I want to filter out lines which has field2="value2". So, I run the following script

A = LOAD 'input.txt' AS line:chararray;
B = FILTER A BY line MATCHES '.*field2="value2".*';
DUMP B;

The above code snippet throws up 0 records. If I don't give the ending double quote, it works

B = FILTER A BY line MATCHES '.*field2="value2.*';

I'd love to know why the former doesn't work.

Upvotes: 1

Views: 666

Answers (1)

Nishu Tayal
Nishu Tayal

Reputation: 20820

Try with the escape chacacter for quotes:

A = LOAD 'input.txt' AS line:chararray;
B = FILTER A BY line MATCHES '.*field2=\\"value2\\".*';
DUMP B;

Upvotes: 1

Related Questions