input a file editing it, output it.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting input a file editing it, output it.
# 1  
Old 05-04-2012
input a file editing it, output it.

i have a file that contains such earthquake data, i want to write an AWK or SED script to input it and fix it (delete each section header delete some field, delete some blank lines and put ### instead of that) and at the end output it to a new file.
here is my file:
Code:
[input]
EventID Date (UTC) Latitude Longitude
20111231234613.8469 31/12/2011 23:46:08 38.6762 43.689
    
TypeID GroupID EventID BulletinID CodeID
1 0 2.01112E+13 1325375174 52
1 0 2.01112E+13 1325375174 290
1 0 2.01112E+13 1325375178 331
1 0 2.01112E+13 1325375179 52
    
    
    
EventID Date (UTC) Latitude Longitude
20111231233115.9433 31/12/2011 23:31:12 38.8528 43.5393
    
TypeID GroupID EventID BulletinID CodeID
1 0 2.01112E+13 1325374276 290
1 0 2.01112E+13 1325374280 52
1 0 2.01112E+13 1325374280 290
    
    
    
EventID Date (UTC) Latitude Longitude
20111231225255.5981 31/12/2011 22:52:52 38.4617 43.2955
    
TypeID GroupID EventID BulletinID CodeID
1 0 2.01112E+13 1325371976 52
1 0 2.01112E+13 1325371978 52
1 0 2.01112E+13 1325371979 102
1 0 2.01112E+13 1325371984 290
1 0 2.01112E+13 1325371984 360
1 0 2.01112E+13 1325371985 102
1 0 2.01112E+13 1325371989 331
1 0 2.01112E+13 1325371992 69
1 0 2.01112E+13 1325371993 360

and here is desired output:
Code:
[desired_output]
31/12/2011 23:46:08 38.6762 43.689 14.16
1 0 2.01112E+13 1325375174 52
1 0 2.01112E+13 1325375174 290
1 0 2.01112E+13 1325375178 331
1 0 2.01112E+13 1325375179 52
###    
31/12/2011 23:31:12 38.8528 43.5393 6.13
1 0 2.01112E+13 1325374276 290
1 0 2.01112E+13 1325374280 52
1 0 2.01112E+13 1325374280 290
###    
31/12/2011 22:52:52 38.4617 43.2955 3.23
1 0 2.01112E+13 1325371976 52
1 0 2.01112E+13 1325371978 52
1 0 2.01112E+13 1325371979 102
1 0 2.01112E+13 1325371984 290
1 0 2.01112E+13 1325371984 360
1 0 2.01112E+13 1325371985 102
1 0 2.01112E+13 1325371989 331
1 0 2.01112E+13 1325371992 69
1 0 2.01112E+13 1325371993 360

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 05-04-2012 at 05:48 AM..
# 2  
Old 05-04-2012
Code:
perl -lane '
if (/^EventID/) { $f = 1 }
elsif (/^\d/ && $f == 1) {
    print "###" unless ($. == 2);
    print join (" ", @F[1..$#F]);
    $f = 0;
}
elsif (/^[a-zA-Z]/ || /^\s+$/) { next }
elsif (/^\d/ && $f == 0) { print join (" ", @F) }
' inputfile

Output:
Code:
31/12/2011 23:46:08 38.6762 43.689
1 0 2.01112E+13 1325375174 52
1 0 2.01112E+13 1325375174 290
1 0 2.01112E+13 1325375178 331
1 0 2.01112E+13 1325375179 52
###
31/12/2011 23:31:12 38.8528 43.5393
1 0 2.01112E+13 1325374276 290
1 0 2.01112E+13 1325374280 52
1 0 2.01112E+13 1325374280 290
###
31/12/2011 22:52:52 38.4617 43.2955
1 0 2.01112E+13 1325371976 52
1 0 2.01112E+13 1325371978 52
1 0 2.01112E+13 1325371979 102
1 0 2.01112E+13 1325371984 290
1 0 2.01112E+13 1325371984 360
1 0 2.01112E+13 1325371985 102
1 0 2.01112E+13 1325371989 331
1 0 2.01112E+13 1325371992 69
1 0 2.01112E+13 1325371993 360

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 05-04-2012
Thank you

well done, thamks a lotSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

creating separate output file for each input file in python

Experts, Need your help for this. Please support My motive is to create seperate output file for each Input Files(File 1 and File2) in another folder say(/tmp/finaloutput) Input files File 1(1.1.1.1.csv) a,b,c 43,17104773,3 45,17104234,4 File 2(2.2.2.2.csv) a,b,c 43,17104773,1... (2 Replies)
Discussion started by: as7951
2 Replies

2. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

5. UNIX for Dummies Questions & Answers

Help with ls to input for simultaneous editing

I just registered today and started unix about a month ago. I'm trying to make a script where I can add commands or text to the end of files in a listing. $ echo "#text_or_command" >> #List of files from ls I can't seem to find/understand it on these fourms. Could it be done at... (4 Replies)
Discussion started by: 62583
4 Replies

6. UNIX for Dummies Questions & Answers

12. If an ‘88’ Record with BAI Code ‘902’ was found on input file and not written to Output file, re

This is my input file like this 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+00000000354,,/ 49,+00000000000416920,00002/ 03,5313236,,015,+00231036992,,,045,+00231036992,,,901,+00000048428,,/ 88,100,+0000000000000,0000000,,400,+0000000000000,0000000,/ 88,902,+0000000079077,,/... (0 Replies)
Discussion started by: sgoud
0 Replies

7. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

8. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

9. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

10. Shell Programming and Scripting

input -output file

Hi, I am having an Input file .which is having a list of names. comapring with our database , needs to write the out put in file called output.txt , format should be name--> country--->phone number could you please help me.. thanks in advance (7 Replies)
Discussion started by: hegdeshashi
7 Replies
Login or Register to Ask a Question