Missing information in output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Missing information in output file
# 1  
Old 11-27-2017
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
Code:
17/11/25 03:43:51:732000 [13431732000 microsec]

but i got
Code:
732000[13431732000microsec]

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

Here the code
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]]=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], (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

Last edited by jiam912; 11-27-2017 at 06:52 AM.. Reason: forget to attach the files
# 2  
Old 11-27-2017
What do you expect with a filed separator : , several FS in your record, and extracting $NF?
What "last records" don't you get?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-27-2017
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
# 4  
Old 11-27-2017
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.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 11-27-2017
RudiC

I try to change
Code:
  fld2=normStr($FN)

to
Code:
 fld2=normStr(substr($0,17,100))

But not always the string start in column 17??
# 6  
Old 11-27-2017
Obviously not. How about checking NF > 2?
This User Gave Thanks to RudiC For This Post:
# 7  
Old 11-28-2017
RudiC,

I try this Smilie

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get specific information from output

Hello community, I'm going crazy to analize an output via shell script and then get some information from it, here is the output: Slot 2 - MMU2 H, RAU2 X 15/A01 XPIC Enabled Autorestore Unknown Slot 3 - MMU2 H, RAU2 X 15/A01 XPIC ... (7 Replies)
Discussion started by: Lord Spectre
7 Replies

2. Shell Programming and Scripting

Fix script to get missing information

Gents, Can you please help me to fix the following script in order to get complete data as desired. I am missing some data in output. the complete input file is attached. The script I am using is awk '{\ status=substr($0,91,2)\ ind=substr($0,26,1);\ ... (10 Replies)
Discussion started by: jiam912
10 Replies

3. Shell Programming and Scripting

Pipe output missing date?

I'd like to have the output from this script piped to a text file that has the date at the beginning of it. For example, my ideal would be something like this $./run_script.sh $ls *.out 2013-Feb-26-output_filename.out Here's the code I'm using. #! /bin/ksh DAT=`date '+%Y-%b-%d'` for... (2 Replies)
Discussion started by: DustinT
2 Replies

4. Shell Programming and Scripting

get specific information from text file or command output

Hello, I would need some help, :wall: on a linux script, I am not sure how can I separate some text file, Text file contains something similar to this: share "userhome_e" "/fs1_100g/FILE58/userhome" umask=022 maxusr=4294967295 netbios=FILE58 share "bu share"... (3 Replies)
Discussion started by: nakaedu
3 Replies

5. Shell Programming and Scripting

Script to output a line missing a number

Ok, Lets see if I can explain this We have a script that pulls information from multiple files and outputs it, however I only need 2 Columns (of 11) from it right now I run the script like this: tkxtrn | awk '{print $5" "" "$9}' This gives me column 5 and 9, the only two I care for ... (5 Replies)
Discussion started by: shadowkraze
5 Replies

6. UNIX and Linux Applications

missing delimiters when mysql output is redirected to log file

Hi, Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3. Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file ~Thanks Step-1: Execute command > mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Discussion started by: newbielgn
3 Replies

7. Shell Programming and Scripting

Using txr to extract information from output

am using txr command (txr 1097) on a process that generates the following output. Im trying to extract the 13th field from the highlighted string. it is delimited by '?'. The 13th field corresponds to the '0' (in bold). can you let me know how I can extract the 13 th field please? ... (1 Reply)
Discussion started by: pazman
1 Replies

8. Shell Programming and Scripting

ksh/awk help - output missing numbers

Here is what I am trying to do: I have a list of numbers that I pulled from an awk command in a column like so: 1 3 4 7 8 I want to find which numbers in the list are missing out of a range. So let's say I want to find out from the list above which numbers are missing from the... (6 Replies)
Discussion started by: afavis
6 Replies

9. AIX

#emgr -l command output missing

Hi, I have recently started to patch all my AIX boxes. I have applied almost 28 interim fixes on those. i have the snaps of emgr -l out put showing all tha patch details and date on which those we applied. but after reboot, emgr -l comannd says "There is no efix data on this... (0 Replies)
Discussion started by: sandeepbodkhe
0 Replies
Login or Register to Ask a Question