0

How can I search for a pattern in awk if the text contains special characters?

billinAddress ||

when I search, it is showing an error on pipe sign ||. How can I search for the pipe sign || in awk?

2 Answers 2

4

You just need to escape them using \. So, instead of writing billinAddress ||, you need to write billinAddress \|\|.

For example, you can search for your pattern using:

awk '/billinAddress \|\|/{ print $0 }' /path/to/file
2
sgeorge-mn:~ sgeorge$ echo 'billinAddress ||' | awk '/\|\|/{ print $0 }'
billinAddress ||
sgeorge-mn:~ sgeorge$ echo 'billinAddress' | awk '/\|\|/{ print $0 }'

You must log in to answer this question.