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. Miller egm2@jps.net | | GnuPG public key: http://www.jps.net/egm2/gpg.asc | +----------------------------------------------------+