In AWK, how to insert the value of variable as string at the beginning of the line -
problem solved: due hidden "ctrl-ms". used following awk code remove them:
awk '{ gsub("\r", ""); print $0;}' i try insert variable string @ beginning lines match.
the updated example, between &&&&&& lines, bit long needed explaining codes. try extract information each case (with unique case # sp 15 xxxx). want insert case numbers @ front of each lines of diagnosis (using variable of "old_case")
&&&&&&
medical record | surgical pathology pg 1 of 2 pathology report accession no. sp 15 1111 submitted by: date obtained: specimen (received ): right, right right right =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= pathology report accession no. sp 15 1111 gross description: specimen received in 1 formalin filled container, labeled microscopic diagnosis: lung, right right right right, left left dx: changes changes changes no evidence of malignancy (please see description) /es/ signature, m.d. &&&&&&
my whole script follows:
#! /bin/awk -f begin { old_case = "0000"; } /accession no./ {if (old_case != $7) {old_case = $7; print "acc#",$5,$6,$7 > "output"} else {}}; /microscopic diagnosis:/ {flag=1;next} /\/es\// || /supplementary/ {flag=0} flag {print old_case,$0 > "output"}; end { } the result got is:
acc# sp 15 1111 1111 lung, right right right right, left left 1111 dx: changes changes changes 1111 no evidence of malignancy 1111 (please see description) 1111 1111 it appears new line breaker added each time variable "old_case" printed. on other hand, if use string "test" instead of variables (with following code)
/microscopic diagnosis:/ {flag=1;next} /\/es\// {flag=0} flag {print "test",$0 > "output"}; the result follows, want get:
acc# sp 15 1111 test lung, right right right right, left left test dx: changes changes changes test no evidence of malignancy test (please see description) test test i using mac osx 10.9.5
Comments
Post a Comment