Get some data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get some data
# 1  
Old 11-01-2012
Get some data

Hi Gents,

I have a long file like this,
Code:
% SL            : 02695.00
% SN            : 07005.00
% SI            : 1
% StackNb       : 1
% FleetNb       : 1
% DsdNb         : 4
% SweepCounter  : 10990
% Sweep  Type   : b1=[CUSTOM S61_DSD]
% Sweep Status  : 1
% Drive         : 75
% Gps Status    : $GPGGA,000115.00,2315.423914,N,05004.325220,E,4,09,1.0,189.495,M,-27.26,M,3,0000*4
% TB            : 12/10/11 00:01:03:560000
% Time Inhibit  : 11
% EXTENDED TIME STATUS :
%     phase               warnings                overloads
%         force   Gv  Gs  masse pist. plaque
%Time         dist        1 2 3 1 2 3 1 2 3 4 5 6 F P M V E
0.5     0   0   0  10 122 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1.0     0   0   0   3 162 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1.5     0   0   0   7 169 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2.0     0   0   0   9 174 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2.5     0   0   0   5 182 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
3.0     0   0   0   3 193 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
3.5     0   0   0  14 197 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
4.0     0   0   0   9 213 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
4.5     0   0   0   7 220 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
5.0     0  41  17  11 201 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
5.5     0  60  29   7  84 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
6.0     2  77  12  22  46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
6.5     0  77  16  15  58 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
7.0     0  77  14  10  66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
7.5    -1  77  14  14  62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
8.0    -1  78  13  16  59 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
8.5    -1  75  13  17  55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
9.0    -1  73  11  17  54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
9.5    -2  71  13  18  45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
10.0    1  65  17  17  26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
10.5    5  62  35  21  18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
11.0    0  62  65  22  14 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
11.5    0   0   0  19  11 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
12.0    0   0   0  15  17 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
% pad up : 12/10/11 00:01:15:726
% pad down : 12/10/11 00:00:21:233
% time up to down : 17650 ms
% time down to pressure switch : 3780 ms
% time down to ready : 3790 ms
% time down to sweep : 38140 ms
% SL            : 02693.00
% SN            : 07005.00
% SI            : 1
% StackNb       : 1
% FleetNb       : 1
% DsdNb         : 4
% SweepCounter  : 10994
% Sweep  Type   : b1=[CUSTOM S61_DSD]
% Sweep Status  : 1
% Drive         : 75
% Gps Status    : $GPGGA,000227.00,2315.395933,N,05004.325767,E,4,09,1.0,189.358,M,-27.26,M,3,0000*
% TB            : 12/10/11 00:02:15:652000
% Time Inhibit  : 11
% EXTENDED TIME STATUS :
%     phase               warnings                overloads
%         force   Gv  Gs  masse pist. plaque
%Time         dist        1 2 3 1 2 3 1 2 3 4 5 6 F P M V E
0.5     0   0   0  13 124 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1.0     0   0   0   3 172 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1.5     0   0   0   7 180 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2.0     0   0   0   8 185 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2.5     0   0   0   4 195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
3.0     0   0   0   3 203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
3.5     0   0   0  10 214 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
4.0     0   0   0   8 235 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
4.5     0   0   0   6 245 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
5.0     0  41  17  15 236 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
5.5    -1  61  29  31 145 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
6.0    -1  75  12  30  56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
6.5     1  77  16  26  68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
7.0    -1  79  15  15  77 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
7.5    -1  77  14  14  76 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
8.0     0  78  14  18  68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
8.5     0  76  10  18  62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
9.0    -2  74  14  19  60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
9.5    -2  72  18  21  56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
10.0   -1  71  17  18  46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
10.5   -1  67  17  17  31 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
11.0    5  63  38  21  23 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
11.5    0   0   0  18  20 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
12.0    0   0   0  16  27 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 
% pad up : 12/10/11 00:02:27:805
% pad down : 12/10/11 00:01:32:165
% time up to down : 16480 ms
% time down to pressure switch : 3640 ms
% time down to ready : 3650 ms
% time down to sweep : 39690 ms

I would like to extract some values, then the output shouldbe like it.

File output
SLSN, TB, pad up, pad down, time up to down, time down to pressure switch, time down to ready, time down to sweep

Code:
26957005, 12/10/11 00:01:03:560000, 12/10/11 00:01:15:726, 12/10/11 00:00:21:233, 17650, 3780, 3790, 38140
26937005, 12/10/11 00:02:15:652000, 12/10/11 00:02:27:805, 12/10/11 00:01:32:165, 16480, 3640, 3650,3650

Thanks ind advance for your help..Smilie

Last edited by Franklin52; 11-01-2012 at 07:56 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 11-01-2012
Code:
awk '/SL/{if(s){print s;s=$NF+0}else{s=$NF+0}}
    /SN/{s=s""$NF+0}
    /TB/{s=s","$(NF-1)" "$NF}
    /pad up/{s=s","$(NF-1)" "$NF}
    /pad down/{s=s","$(NF-1)" "$NF}
    /time up to down/{s=s","$(NF-1)}
    /time down to pressure switch/{s=s","$(NF-1)}
    /time down to ready/{s=s","$(NF-1)}
    /time down to sweep/{s=s","$(NF-1)}
    END{print s}' file

# 3  
Old 11-01-2012
Code:
perl -lne 'BEGIN{@id=split(/,/,"SL,SN, TB, pad up, pad down, time up to down, time down to pressure switch, time down to ready, time down to sweep");}
{for $id (@id){/$id\s*:\s*(.*?)\s*(ms)*$/g;push(@arr,$1) if defined($1);}
if(/time down to sweep/){$arr[0]=int($arr[0]).int($arr[1]);$arr[1]=undef;
print join(", ",grep{defined}@arr);$#arr=-1;}else{next;}}' input_file

This User Gave Thanks to msabhi For This Post:
# 4  
Old 11-01-2012
Dear Pamu, thanks a lot the code works perfect.. thanks for your great job

---------- Post updated at 08:18 AM ---------- Previous update was at 07:51 AM ----------

msabhi Image , thanks for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

3. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

4. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

5. UNIX for Dummies Questions & Answers

How to get data only inside polygon created by points which is part of whole data from file?

hiii, Help me out..i have a huge set of data stored in a file.This file has has 2 columns which is latitude & longitude of a region. Now i have a program which asks for the number of points & based on this number it asks the user to enter that latitude & longitude values which are in the same... (7 Replies)
Discussion started by: reva
7 Replies

6. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

7. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

8. Shell Programming and Scripting

how to verify that copied data to remote system is identical with local data.

I have created simple shell script #!/bin/sh echo `date`; echo "Start .... find . -mtime +95 -print > /tmp/files.txt for file in `cat /tmp/files.txt` do echo "copying file - $file" /usr/local/bin/scp -p -P 2222 $file remote.hostname:/file/path echo "copid file -... (3 Replies)
Discussion started by: ynilesh
3 Replies

9. UNIX for Dummies Questions & Answers

Howto capture data from rs232port andpull data into oracle database-9i automatically

Hi, i willbe very much grateful to u if u help me out.. if i simply connect pbx machine to printer by serial port RS232 then we find this view: But i want to capture this data into database automatically when the pbx is running.The table in database will contain similar to this view inthe... (1 Reply)
Discussion started by: boss
1 Replies
Login or Register to Ask a Question