Hello,
I need to modify an awk script to recognize the last field $NF when the line is split over more than 1 line.
In my input file the field separator is the exclamation mark ! so FS="!"
So here is my input file infile.txt, it has 2 records, the field separator is in bold:
INPUT
4888689!?!Change of PROD
!TX!?!DETAILS
!US!?!?!file_937_20101024_065520.txt
48887370!Change of PROD!?!?!cmt_det3_937_20101024_065520.txt
Before I do anything in the AWK script I need to be able recognize the last field for each line type.
For record type #1 the $NF (last field) is on a different line (I need to be able to get the last field for these) (AWK recognizes record one as being 3 different lines) ($NF would be file_937_20101024_065520.txt)
For record type #2 the $NF (last field) is on the same line (this is the way AWK would read most of them) ($NF would be cmt_det3_937_20101024_065520.txt)
So the rule would be:
If the field separator is the 1st character on the line then look at the previous line until the line does not start with the field separator and so then
$1 would be on the first line and the $NF will be at the end of the last line.
Then print the lines to an output file
OUTPUT
4888689!?!Change of PROD!TX!?!DETAILS!US!?!?!file_937_20101024_065520.txt
48887370!Change of PROD!?!?!cmt_det3_937_20101024_065520.txt