parse text file
parse text file
(OP)
hi all:
I have just registred to start a new thread regarding use of awk to parse text file and I' m new in awk language
I took a portion of data from texte file :
I have parsed the text file with this code . test file is texte file example.
I want to get bellow data :
I cant figured out how to do that any help will be appreciated .
thanks
I have just registred to start a new thread regarding use of awk to parse text file and I' m new in awk language
I took a portion of data from texte file :
CODE -->
DATA DATA GHR1 BRAND TRUE LST 115-34-SPECT 115-42-SPECT 115-50-SPECT BRAND FALSE LIST 115-34-SPECT 115-42-SPECT 115-50-SPECT END
I have parsed the text file with this code . test file is texte file example.
CODE -->
awk -v '/^DATA/&& /BRAND/ {if(NR>1) print "DATAFIRST=" getline }' test
I want to get bellow data :
CODE -->
DATAFIRST=GHR1,LSIT=115-34-SPECT,BLOC,BRAND=TRUE; DATAFIRST=GHR1,LSIT=115-42-SPECT,BLOC,BRAND=TRUE; DATAFIRST=GHR1,LSIT=115-50-SPECT,BLOC,BRAND=TRUE; DATAFIRST=GHR1,LSIT=115-34-SPECT,DEBLOC,BRAND=FALSE; DATAFIRST=GHR1,LSIT=115-42-SPECT,DEBLOC,BRAND=FALSE; DATAFIRST=GHR1,LSIT=115-50-SPECT,DEBLOC,BRAND=FALSE;
I cant figured out how to do that any help will be appreciated .
thanks
RE: parse text file
I tried this
seifou45.awk
CODE
and got this result with data file you provided above:
CODE
RE: parse text file
sorry for my late response I was sick .
the scipt works fine thanks a lot of .
just last thing can you explain please the script .
for example :
data_nr it is a variable assigned to NR number of recored and in the next block NR == data_nr+1 new assignement with commparison incremented ?
thanks
RE: parse text file
The blocks are executed only when the condition fits,
for example:
This block
CODE
This block will be executed only on the line which follows the line which contains the string "DATA"
CODE
To understand how it works insert some print statements and look at an awk tutorial or manual
https://www.tutorialspoint.com/awk/index.htm
https://www.gnu.org/software/gawk/manual/gawk.html