Groups | Search | Server Info | Login | Register
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: Regular expression in awk |
| Date | 2011-04-06 19:24 +0200 |
| Organization | (posted via) M-net Telekommunikations GmbH |
| Message-ID | <ini7kr$410$1@news.m-online.net> (permalink) |
| References | <4e09d4fd-8351-45f0-8f17-b6ac0d32e19a@l18g2000yql.googlegroups.com> |
On 06.04.2011 16:40, gio001 wrote:
> Hello,
> I have thousand of messages (HL7),
Provide sample data for a few HL7 records.
> I want to use awk to extract only
> the ones that have a particular value in pv1.18
Define what you mean by "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
You mean a single ASCII CR character separates some entity in the data?
> segments.
Define what a segment in your sample data is.
> I would like to use a line somewhat like:
>
> awk '{if(/PV1\|\([^|]*\|\)\{16\}\|X/){print $0}}' infile > outfile
In awk you can write
/pattern/ { action }
instead of
{ if ($0 ~ /pattern/) action }
>
> I do not seem to be able to get this working properly in awk on a AIX
> box.
> Yet this statement works fine against the infile:
>
> grep 'PV1\|\([^|]*\|\)\{16\}\|X' infile
Gee! What's that cryptic expression supposed to do?
Please don't try to give your cryptic tries without explaining what you
actually want to achieve.
>
> Can anyone please help?
It may help you to know that in awk you can define the field separator
and record separators. Then you can access individual fields in a simple
way. Say, your field separator is | (a pipe symbol) and you want to
extract the 18th field only in lines where you've some pattern /PV1/:
awk -F\| '/PV1/ { print $18 }' infile
Janis
> Thanks.
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
Regular expression in awk gio001 <gcrippa@gmail.com> - 2011-04-06 07:40 -0700
Re: Regular expression in awk pk <pk@pk.invalid> - 2011-04-06 16:01 +0100
Re: Regular expression in awk Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-06 19:24 +0200
Re: Regular expression in awk Manuel Collado <m.collado@domain.invalid> - 2011-04-06 21:07 +0200
Re: Regular expression in awk gio001 <gcrippa@gmail.com> - 2011-04-06 12:25 -0700
Re: Regular expression in awk Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-06 23:09 +0200
Re: Regular expression in awk gio001 <gcrippa@gmail.com> - 2011-04-06 19:59 -0700
Re: Regular expression in awk Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-04-07 07:32 +0000
Re: Regular expression in awk gio001 <gcrippa@gmail.com> - 2011-04-07 05:06 -0700
Re: Regular expression in awk Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-04-07 13:34 +0000
Re: Regular expression in awk gio001 <gcrippa@gmail.com> - 2011-04-07 08:27 -0700
Re: Regular expression in awk Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-04-07 18:32 +0000
Re: Regular expression in awk Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-04-07 13:34 +0100
Re: Regular expression in awk arnold@skeeve.com (Aharon Robbins) - 2011-04-07 13:31 +0000
Re: Regular expression in awk Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2011-04-08 13:18 +0100
csiph-web