Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

migrated from serverfault.com Jan 14 '13 at 0:33

This question came from our site for professional system and network administrators.

2 Answers

sgeorge-mn:~ sgeorge$ echo 'billinAddress ||' | awk '/\|\|/{ print $0 }'
billinAddress ||
sgeorge-mn:~ sgeorge$ echo 'billinAddress' | awk '/\|\|/{ print $0 }'
share|improve this answer
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.