How to get multiple rows from a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get multiple rows from a file?
# 1  
Old 11-12-2012
How to get multiple rows from a file?

Gents,

I have a big file, where I would like to get some rows..

Then file1 contains.

Code:
Obs_Report_Result : [                                                           
                                                                                
# ===== (1) =====                                                               
Observer_Report : [                                                             
# ===============                                                               
                                                                                
  Version         : "5.0"                                                             
  Exploitation_Mode     : SLIP SWEEP                                               
                                                                                
  Line_Report     : [                                                              
    Filter_Type             : 8N LIN                                                     
    Aux_Nb_Trace         : 5                                                          
    Seis_Nb_Trace         : 3840                                                      
    Total_Nb_Trace         : 3845                                                     
    Nb_Of_Dead_Seis_Channels     : 0                                               
    Nb_Of_Live_Seis_Channels     : 3840                                            
    Dead_Seis_Channels         :                                                      
    Live_Seis_Channels         : 2856:7121-7360(1-240)                                
                             2866:7121-7360(241-480)                                  
                             2876:7121-7360(481-720)                                  
                             2886:7121-7360(721-960)                                  
                             2896:7121-7360(961-1200)                                 
                             2906:7121-7360(1201-1440)                                
                             2916:7121-7360(1441-1680)                                
                             2926:7121-7360(1681-1920)                                
                             2936:7121-7360(1921-2160)                                
                             2946:7121-7360(2161-2400)                                
                             2956:7121-7360(2401-2640)                                
                             2966:7121-7360(2641-2880)                                
                             2976:7121-7360(2881-3120)                                
                             2986:7121-7360(3121-3360)                                
                             2996:7121-7360(3361-3600)                                
                             3006:7121-7360(3601-3840)                                
    SFL                 : 2856                                                              
    SFN                 : 7121                                                              
    Spread_Nb             : 105                                                          
    Spread_Type             : ABSOLUTE                                                   
    Acq_Error             :                                                              
    ITB                 : FALSE                                                             
  ]                                                                             
                                                                                
  Shot_Report     : [                                                              
    Swath_Name             : 1162                                                        
    Swath_ID             : 61                                                            
    Shot_Nb             : 425                                                            
    Line_Name             :  2775.0                                                      
    Point_Number         :  7240.0                                                    
    Point_Index             : 1                                                          
    Acq_Length             : 18000 # (msec)                                              
    Sweep_Length         : 12000 # (ms)                                               
    Pilot_Length         : 12000 # (ms)                                               
    Record_Length         : 6000 # (ms)                                               
    Sample_Rate             : 2000                                                       
    Total_Nb_Sample         : 3001                                                    
    Type_Of_Source         : VIBRO                                                    
    Source_Nb             : 4                                                            
    Tb_Window             : 20000                                                        
    Date             : Wed Oct 31 00:00:28 2012                                          
                                                                                
    Julian_Day             : 305                                                         
    Cog_State             : ACTUAL                                                       
    Cog_Easting             : 416875.0                                                   
    Cog_Northing         : 2574281.4                                                  
    Cog_Elevation         : 151.1                                                     
    Cog_Deviation         :    6.4                                                    
    Uphole_Time             :  0.00 # (msec)                                             
  ]                                                                             
                                                                                
  Noise_Report     : [                                                             
    Noise_Elim_type         : NE OFF                                                  
    Thres_Hold_Var         : N/A                                                      
    Hist_Editing_Type         : N/A                                                   
    Hist_Range             : N/A # (dB)                                                  
    Hist_Taper_Length         : N/A # (power)                                         
    Hist_Thres_Init_Val         : N/A # (dB)                                          
    Hist_Zeroing_Length         : N/A # (msec)                                        
    Low_Trace_Value         : 0 # (dB)                                                
    Low_Trace_Percent         : 0                                                     
    Noisy_Trace_Percent         : N/A                                                 
    Low_Noisy_Verbose         :                                                       
    Nb_Of_Window         : 0                                                          
  ]                                                                             
                                                                                
  Process_Report     : [                                                           
    Type_Of_Process         : CORREL BEFORE                                           
    Acq_Nb             : 1                                                               
    Correl_Pilot_Nb         : 3                                                       
    Auto_Cor_Peak_Time         : 1000                                                 
    Dump_Stacking_Fold         : 1                                                    
    Max_Of_Max_Aux_Char         : "   2.444985e+16"                                   
    Max_Of_Max_Seis_Char     : "   1.146503e+12"                                   
    Max_Time_Value_Verbose     : "0/1 : 0 455506.22"                               
    Tb_GPS_Time             : 1035666044616001                                           
  ]                                                                             
                                                                                
  Record_Report         : [                                                           
    File_Nb             : 617                                                            
    Type_Of_Dump         : DUMP                                                       
    Type_Of_Test         : N/A 3                                                      
    Tape_Nb             : 6589                                                           
    Tape_Label             : "N7"                                                        
    Record_Type             : NORMAL                                                     
    Blocking_Mode         : FALSE                                                     
    Device_Bypass         : FALSE                                                     
    Tape_Error_Text         : ""                                                      
    Tape_Time             : "Wed Oct 31 00:01:27 2012                                    
"                                                                               
    File_Count             : "609                                                        
    File_Per_Tape         : "9999"                                                    
  ]                                                                             
                                                                                
  Comment             : "N/A"                                                            
  User_Header             : ""                                                           
                                                                                
                                                                                
]                                                                               
# ===== (2) =====                                                               
Observer_Report : [                                                             
# ===============                                                               
                                                                                
  Version         : "5.0"                                                             
  Exploitation_Mode     : SLIP SWEEP                                               
                                                                                
  Line_Report     : [                                                              
    Filter_Type             : 8N LIN                                                     
    Aux_Nb_Trace         : 5                                                          
    Seis_Nb_Trace         : 3840                                                      
    Total_Nb_Trace         : 3845                                                     
    Nb_Of_Dead_Seis_Channels     : 0                                               
    Nb_Of_Live_Seis_Channels     : 3840                                            
    Dead_Seis_Channels         :                                                      
    Live_Seis_Channels         : 2856:7131-7370(1-240)                                
                             2866:7131-7370(241-480)                                  
                             2876:7131-7370(481-720)                                  
                             2886:7131-7370(721-960)                                  
                             2896:7131-7370(961-1200)                                 
                             2906:7131-7370(1201-1440)                                
                             2916:7131-7370(1441-1680)                                
                             2926:7131-7370(1681-1920)                                
                             2936:7131-7370(1921-2160)                                
                             2946:7131-7370(2161-2400)                                
                             2956:7131-7370(2401-2640)                                
                             2966:7131-7370(2641-2880)                                
                             2976:7131-7370(2881-3120)                                
                             2986:7131-7370(3121-3360)                                
                             2996:7131-7370(3361-3600)                                
                             3006:7131-7370(3601-3840)                                
    SFL                 : 2856                                                              
    SFN                 : 7131                                                              
    Spread_Nb             : 109                                                          
    Spread_Type             : ABSOLUTE                                                   
    Acq_Error             :                                                              
    ITB                 : FALSE                                                             
  ]                                                                             
                                                                                
  Shot_Report     : [                                                              
    Swath_Name             : 1162                                                        
    Swath_ID             : 61                                                            
    Shot_Nb             : 456                                                            
    Line_Name             :  2773.0                                                      
    Point_Number         :  7250.0                                                    
    Point_Index             : 1                                                          
    Acq_Length             : 18000 # (msec)                                              
    Sweep_Length         : 12000 # (ms)                                               
    Pilot_Length         : 12000 # (ms)                                               
    Record_Length         : 6000 # (ms)                                               
    Sample_Rate             : 2000                                                       
    Total_Nb_Sample         : 3001                                                    
    Type_Of_Source         : VIBRO                                                    
    Source_Nb             : 3                                                            
    Tb_Window             : 20000                                                        
    Date             : Wed Oct 31 00:00:46 2012                                          
                                                                                
    Julian_Day             : 305                                                         
    Cog_State             : ACTUAL                                                       
    Cog_Easting             : 417375.0                                                   
    Cog_Northing         : 2574227.9                                                  
    Cog_Elevation         : 149.8                                                     
    Cog_Deviation         :    2.8                                                    
    Uphole_Time             :  0.00 # (msec)                                             
  ]                                                                             
                                                                                
  Noise_Report     : [                                                             
    Noise_Elim_type         : NE OFF                                                  
    Thres_Hold_Var         : N/A                                                      
    Hist_Editing_Type         : N/A                                                   
    Hist_Range             : N/A # (dB)                                                  
    Hist_Taper_Length         : N/A # (power)                                         
    Hist_Thres_Init_Val         : N/A # (dB)                                          
    Hist_Zeroing_Length         : N/A # (msec)                                        
    Low_Trace_Value         : 0 # (dB)                                                
    Low_Trace_Percent         : 0                                                     
    Noisy_Trace_Percent         : N/A                                                 
    Low_Noisy_Verbose         :                                                       
    Nb_Of_Window         : 0                                                          
  ]                                                                             
                                                                                
  Process_Report     : [                                                           
    Type_Of_Process         : CORREL BEFORE                                           
    Acq_Nb             : 1                                                               
    Correl_Pilot_Nb         : 3                                                       
    Auto_Cor_Peak_Time         : 1000                                                 
    Dump_Stacking_Fold         : 1                                                    
    Max_Of_Max_Aux_Char         : "   2.444985e+16"                                   
    Max_Of_Max_Seis_Char     : "   1.224311e+12"                                   
    Max_Time_Value_Verbose     : "0/1 : 0 455009.75"                               
    Tb_GPS_Time             : 1035666062640001                                           
  ]                                                                             
                                                                                
  Record_Report         : [                                                           
    File_Nb             : 618                                                            
    Type_Of_Dump         : DUMP                                                       
    Type_Of_Test         : N/A 3                                                      
    Tape_Nb             : 6589                                                           
    Tape_Label             : "N7"                                                        
    Record_Type             : NORMAL                                                     
    Blocking_Mode         : FALSE                                                     
    Device_Bypass         : FALSE                                                     
    Tape_Error_Text         : ""                                                      
    Tape_Time             : "Wed Oct 31 00:01:32 2012                                    
"                                                                               
    File_Count             : "610                                                        
    File_Per_Tape         : "9999"                                                    
  ]                                                                             
                                                                                
  Comment             : "N/A"                                                            
  User_Header             : ""

File output..desired.

Code:
 Swath_Name, Swath_ID, Shot_Nb, Line_Name, Point_Number, Tb_GPS_Time, File_Nb, Type_Of_Dump, Type_Of_Test, Tape_Nb, Tape_Label, Date, Comment  
 1162, 61, 425, 2775.0, 7240.0, 1035666044616001, 617, DUMP, N/A 3, 6589,  "N7", Wed Oct 31 00:00:46 2012, "N/A" 
 1162, 61, 456, 2773.0, 7250.0, 1035666062640001, 618, DUMP, N/A 3, 6589,  "N7", Wed Oct 31 00:01:32 2012, "N/A"

Thanks ind advance for your help..
# 2  
Old 11-12-2012
With assumptions:
Code:
awk 'BEGIN{
head="Swath_Name,Swath_ID,Shot_Nb,Line_Name,Point_Number,Tb_GPS_Time,File_Nb,Type_Of_Dump,Type_Of_Test,Tape_Nb,Tape_Label,Date,Comment"
maxitems=split(head,name,/,/)
for(i in name) num[name[i]]=i}
/^Observer_Report/{f=1;s++;next}
$1 in num{t=$1;$1=$2="";data[s,t]=$0}
END{
if(f)
{
 print head;
 for(i=1;i<=s;i++)
 {
  for(j=1;j<=maxitems;j++)
   printf("%s%s",(j==1?"":","),data[i,name[j]])
  printf "\n"
 }
}
}' file

# 3  
Old 11-12-2012
Dear elixier,

Thanks for your quick reply,

I got something like:

Code:
,  "N/A" v 11 00:00:46 2012
,  "N/A" v 11 00:01:32 2012

Regards,
# 4  
Old 11-13-2012
Some help please..
Thanks
# 5  
Old 11-13-2012
Code:
awk -F: 'BEGIN {
print "Swath_Name,Swath_ID,Shot_Nb,Line_Name,Point_Number,Tb_GPS_Time,File_Nb,Type_Of_Dump,Type_Of_Test,Tape_Nb,Tape_Label,Date,Comment";
}
/(Swath_Name|Swath_ID|Shot_Nb|Line_Name|Point_Number|Tb_GPS_Time|File_Nb|Type_Of_Dump|Type_Of_Test|Tape_Nb|Tape_Label|Date|Comment)/ {
sub("^[ \t]*","",$2);sub("[ \t]*$","",$2); if($1 ~ /Comment/) { printf "%s\n", $2; } else { printf "%s,", $2; }
} ' infile

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

2. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

3. UNIX for Dummies Questions & Answers

Write the total number of rows in multiple files into another file

Hello Friends, I know you all are busy and inteligent too... I am stuck with one small issue if you can help me then it will be really great. My problem is I am having some files i.e. Input.txt1 Input.txt2 Input.txt3 Now my task is I need to check the total number of rows in... (4 Replies)
Discussion started by: malaya kumar
4 Replies

4. Shell Programming and Scripting

connecting to table to extract multiple rows into file from unix script

I need to extract the data from oracle table and written the below code. But it is not working.There is some problem with the query and output is shown is No rows selected" . If I run the same query from sql developer there is my required output. And if I run the shell script with simple sql... (7 Replies)
Discussion started by: giridhar276
7 Replies

5. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

6. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

7. UNIX for Dummies Questions & Answers

Converting rows into multiple-rows

Hi every one; I have a file with 22 rows and 13 columns which includes floating numbers. I want to parse the file so that every five columns in the row would be a new record (row). For example, the first line in the old file should be converted into three lines with first two lines contain 5... (6 Replies)
Discussion started by: PHL
6 Replies

8. Shell Programming and Scripting

grep multiple rows from file.

Hi, I have file1 that contains many columns as show the first three below: "At1g29930" 198 2105 "At5g46430" 5569 9576 "At1g64740" 1908 2505 "At5g46430" 6717 11317 "At1g64740" 453 655 "At1g12470" 33 18 "At1g80680" 149 262 "At1g23040" ... (3 Replies)
Discussion started by: yifangt
3 Replies

9. Shell Programming and Scripting

extract multiple cloumns from multiple files; skip rows and include filenames; awk

Hello, I am trying to write a bash shell script that does the following: 1.Finds all *.txt files within my directory of interest 2. reads each of the files (25 files) one by one (tab-delimited format and have the same data format) 3. skips the first 10 rows of the file 4. extracts and... (4 Replies)
Discussion started by: manishabh
4 Replies

10. Shell Programming and Scripting

How to handle multiple rows in a file

I have a FILE a.txt which has the following data 113901.94,113901.94,56950.97,56950.97,NOT MATCHING,NOT MATCHING 10693.04,10693.04,5346.52,5346.52,NOT MATCHING,NOT MATCHING 1901.94,1901.94,550.97,550.97,NOT MATCHING,NOT MATCHING 103.04,103.04,53.52,53.52,NOT MATCHING,NOT MATCHING #### This... (2 Replies)
Discussion started by: ksmbabu
2 Replies
Login or Register to Ask a Question