awk reg expression

Hello,
I have thousand of messages (HL7), I want to use awk to extract only the ones that have a particular value in pv1.18
Each record in the file is the whole HL7 message, ie. when I print $0 I get the whole message MSH EVN PID etc. ,there is an x0d between the segments.
I would like to use a line somewhat like:

awk ' /PV1\|(.*\|){17}X\|/ {print $0}' filein > fileout

to get the records out in file out that only have a pv1.18 of X.
I do not seeem to get this working, I am sure I need to correct my regexp.
Anybody please help!
Thanks.

I got moving on this, this grep works :

 grep 'PV1\|\([^|]*\|\)\{16\}\|X' infile

yet this awk does not:

awk '/PV1\|\([^|]*\|\)\{16\}\|X/  {print $0}' infile 

Can anyone suggest what to do ?
Thanks!

With GNU awk you may need the --posix parameter:

$ awk --posix '/PV1\|(.*\|){16}X\|/ { print $0 }' infile
PV1|two|three|four|5|6|7|8|9|10|11|12|13|14|15|16|17|X|rest|of|string

Idea, how about using | as FS

awk -F\| '$1=="PV1" && $18=="X"' infile

I have this working with grep

grep 'PV1\|\([^|]*\|\)\{16\}\|X' infile > outfile 

but the same regexp does not work in awk:

awk '/PV1\|\([^|]*\|\)\{16\}\|X/ {print $0}' infile > outfile

Any idea what I can correct in the awk statement?
Thanks

Does your awk have the --posix argument?

---------- Post updated at 07:26 AM ---------- Previous update was at 07:04 AM ----------

Dosn't work properly for me:

$ grep 'PV1\|\([^|]*\|\)\{16\}\|X' infile
PV1-This shouldn't Match!
PV1|two|three|four|5|6|7|8|9|10|11|12|13|14|15|16|17|X|rest|of|string

Something like this seems right for grep:

grep -E 'PV1\|([^|]*\|){16}X\|' infile

Awk turns out to be pretty similar, note some awks (GNU) require --posix others don't

 awk --posix '/PV1\|([^|]*\|){16}X\|/ { print $0 }' infile