Find multiple values in different lines using command-line | CMD -


i have multiple results (radiology, labs, pathology, transcriptions) same patient in file , interested in getting results set of particular values. example: want radiology report on first line , patient mrn 123456789 on second line. can achieved using findstr? thanks

msh|^~\&|radiology|1|scm||20150303||oru|20150303|t|2.3|20150303 pid||1111111|123456789^^^mrn_sb^||test^patient^^^||19000101||^^|| pv1|1|e|er^er^1^sb|||||||||||||||||||||||||||||||||||||||||||||| orc|re|36543654|36543654|3003487889 

@echo off setlocal :: remove variables starting $  /f "delims==" %%a in ('set $ 2^>nul') set "%%a=" set "found=" set "mrn=%1" /f "delims=" %%o in (q29931949.txt) (  /f "tokens=1-4delims=|" %%a in ("%%o") (   if defined found if "%%a"=="pid" (    set "$2=%%o"    call :report "%%b" "%%c" "%%d"   )   set "found="   if "%%a"=="msh" if "%%b"=="radiology" set found=y   if "%%a"=="msh" if "%%c"=="radiology" set found=y   if defined found set "$1=%%o"  ) )  goto :eof  :report set "field=%~1" if not defined field goto :eof /f "tokens=1delims=^^" %%r in ("%~1") set "field=%%r" if "%field%"=="%mrn%"  /f "tokens=1*delims==" %%r in ('set $') echo(%%s shift goto report 

i used file named q29931949.txt containing data testing.

you don't supply enough information produce result. instance, "mrn" required data item?

this procedure find 2 consecutive lines, first 1 having "msh" in first column , "radiology" in second or third , second line having "pid" in first column snd either second, third or fourth column containing target number.

you'd run routine using thisbatchaname 123456789

it accepts parameter 123456789 , assigns mrn.

it reads file , assigns each line in tun %%o, , tokenises line on |, applying tokens 1-4 %%a..%%d rspectively.

the main loop sets found empty , y if first field msh , second or thid radiology. if found flag set, original line in %%o applied $1. if found set @ start of loop (which means previous line msh/radiology) routine :report called after $2 has original contents of second line assigned.

the :report routine sets field first parameter see whether there remaining parameters process. for assigns part of field first caret (^) field. if matches mrn input command line, $ variables echoed console (you don't want data). regardless, remaining parameters checked.

the reson checking second/third(/fourth) parameter cater presence or absence of data in fields consecutive | characters interpreted single delimiter.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -