Re: Sed script

1999-10-22 Thread Eric G . Miller
On Fri, Oct 22, 1999 at 04:28:29PM +1300, [EMAIL PROTECTED] wrote:
 Hi
 
 Not debian related but i need help nonetheless.
 
 i need to extract the number 997841138254, or any other number from that
 position, from an hl7 file.  The file will look like this :
 
 MSH...OBR|0001||997841138254|..F
 
 I can use OBR as the starting point of the search and then use the | to
 move to the begginning of the number...
 
 What would be the best way of doing this.. maybe i can use a vi script to
 search and extract the number for me.  I don't know how to select a segment
 of a line and write that to a file though.. i am not too familiar with sed
 although i would like to be as it seems rather powerful :)  Any suggestions
 would be appreciated.
 

Not sed, but:

#!/usr/bin/perl -w

while() {
@array = split /\|/, $_;
print $array[3]\n if $#array  3;
}

You might have to change the subscipts. Use it like

$ ./mysplit.pl  myfile.txt
-- 
++
| Eric G. Milleregm2@jps.net |
| GnuPG public key: http://www.jps.net/egm2/gpg.asc  |
++


Re: Sed script

1999-10-22 Thread Eric G . Miller
Duh, even easier:

$ cut --delimiter='|' --fields=N   infile  outfile

where N = the fields you want. See man cut.
-- 
++
| Eric G. Milleregm2@jps.net |
| GnuPG public key: http://www.jps.net/egm2/gpg.asc  |
++


Re: Sed script

1999-10-22 Thread Joakim Svensson

Hi all,

i need to extract the number 997841138254, or any other number from that
position, from an hl7 file.  The file will look like this :

MSH...OBR|0001||997841138254|..F

I can use OBR as the starting point of the search and then use the | to
move to the begginning of the number...

Ok here is an idea how to do it in awk.

awk -v FS=| '{ if ( $1 ~ /OBR/ ) print $4; }'

Could ofcourse be made more advanced if the mumber of | preceeding ORB
is changing.

Runs on the command line or inside vim (vi).
In vim:
:%! awk -v FS=| '{ if ( $1 ~ /OBR/ ) print $4; }'

Hope it helped

Best regards
Joakim