Missing information in output file

Gents,

Using the following code i am able to output the information i need, but some of the strings are not complete due to the separator : used..

Kindly can u help me to get all string after the first :

Example in the output file column 16 i should get

17/11/25 03:43:51:732000 [13431732000 microsec]

but i got

732000[13431732000microsec]

And also i don't understand why i dont get information for last records

Here the code

awk 'BEGIN {
      qq="\""
      tab=sprintf("\t")

      FS=":"
      OFS=","

fldL="SL,SN,SI,StackNb,FleetNb,DsdNb,SweepCounter,SweepType,SweepStatus,Drive,GpsStatus,GNGSA,GNGST,GPZDA,PTNL,TB,QCtype,TimeInhibit,timeendofprevsweeptoup,padup,paddown,timeuptodown,timedowntopressureswitchON,timedowntoready,timedowntosweep,sweeplength"

     fldN=split(fldL, fldT, OFS)
      for(i=1; i in fldT; i++)
        fldA[fldT]=i

      print fldL
}

function normStr(str)
{
   gsub("[" OFS qq tab " ]", "", str)
   return str
}

function arrayFull(a,   i)
{
  for(i=1; i<= fldN; i++)
     if (!(i in a))
        return 0
 return 1
}

arrayFull(outputA) {
  for(i=1; i in outputA; i++)
      printf("%s%s", outputA, (i==fldN)?ORS:OFS)
  split("", outputA)
}
normStr($1) in fldA {
   fld1=normStr($1)
   fld2=normStr($NF)
   if (normStr($2) == "[") {
       getline fld2
       fld2=normStr(fld2)
   }
   outputA[fldA[fld1]]=fld2
}' file1.txt > test.csv

Attached the input file and output file i got

Appreciate your help

What do you expect with a filed separator : , several FS in your record, and extracting $NF ?
What "last records" don't you get?

1 Like

Hi RudiC

Yes, i see there are few separators in the strings, that is the reason i say to select all strings after the first : (separator).
The last record is the last part in the input. I should get 3 rows + header in .csv file .. but i got only 2 rows + headers.

Hope u can help.

Tks a lot

Without digging deeper, I'd say that on the last line, "sweep length" is not set in outputA, arrayFull returns 0, nothing is printed, the data file ends and the script exits.

1 Like

RudiC

I try to change

  fld2=normStr($FN)

to

 fld2=normStr(substr($0,17,100))

But not always the string start in column 17??

Obviously not. How about checking NF > 2 ?

1 Like

RudiC,

I try this :slight_smile:

awk '/SL/{if(s){print s;s=$NF+0}else{s=$NF+0}}
    	/SN/{s=s";"$NF+0}
	/SI/{s=s";"$NF}          
	/StackNb/{s=s";"$NF}      
	/FleetNb/{s=s";"$NF}      
	/DsdNb/{s=s";"$NF}       
	/SweepCounter/{s=s";"$NF} 
	/Sweep  Type/{s=s";"substr($0,19,19)}   
	/Sweep Status/{s=s";"$NF}
	/Drive/{s=s";"$NF}
	/Gps Status/{s=s";"$NF}
	/GNGSA/{s=s";"$NF}     
	/GNGST/{s=s";"$NF}        
	/GPZDA/{s=s";"$NF}         
	/PTNL/{s=s";"$NF}         
	/TB/{s=s";"substr($0,19,47)}            
	/QC type/{s=s";"$NF}	    
	/Time Inhibit/{s=s";"$NF}  
	/time end of prev sweep to up/{s=s";"substr($0,36,13)}    
	/pad up/{s=s";"substr($0,36,23)}                          
	/pad down/{s=s";"substr($0,36,23)}                       
	/time up to down/{s=s";"substr($0,36,13)}                 
	/time down to pressure switch ON/{s=s";"substr($0,36,13)} 
	/time down to ready/{s=s";"substr($0,36,13)}              
	/time down to sweep/{s=s";"substr($0,36,13)}             
	/sweep length/{s=s";"substr($0,36,13)}                   
END{print s}' file1.txt > tmp1


cat tmp1 | awk -F";" 'BEGIN{printf"SL;SN;SI;StackNb;FleetNb;DsdNb;SweepCounter;SweepType;SweepStatus;Drive;GpsStatus;GNGSA;GNGST;GPZDA;PTNL;TB;QCtype;TimeInhibit;timeendofprevsweeptoup;padup;paddown;timeuptodown;timedowntopressureswitchON;timedowntoready;timedowntosweep;sweeplength\n"}
	{print $0 }' >  tmp2.txt


---------- Post updated 11-28-17 at 12:21 AM ---------- Previous update was 11-27-17 at 08:14 AM ----------

RudiC,

Kindly, did u find other solution to get the output needed.

I didn't pursue this as you found a solution yourself, although I was surprised by you abandoning the promising and elegant generic approach presented in post#1.

1 Like

RudiC,
Kindly can u fix the post #1 to get the requested output.. I try but i cant
tks a lot