Split a file by start and end row.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split a file by start and end row.
# 1  
Old 10-21-2015
Split a file by start and end row.

I have a file which looks something as following, I would like to split to several files, The start and end of each file is 'FILE' and end with 'ASCII... ' .
At the same time for each file in the first column add 100 and also second column add 100 the rest of the column as it is , see example of the result file1 . the name of the file it doesnot matter :
Code:
FILE
A header exampe 
this a test example
1000 3000 9000 3200
1100 3000 9100 3200
1200 3100 9200 3200
1300 3200 9300 3200
1200 3050 9400 3200
ASCII file 1
FILE 2
A header exampe
this a test example
1000 3000 8000 3200
4100 4000 8100 3200
5200 6100 8200 3200
1390 5200 8300 3200
1220 3050 8400 3200
ASCII file 2
FILE 3
A header exampe
this a test example
2000 3000 9000 3200
2100 3000 9100 3200
3200 3100 9200 3200
4300 3200 9300 3200
5200 3050 9400 3200
ASCII file 3
.........

The result would be e.g. file 1
Code:
file
A header exampe 
this a test example
1100 3100 9000 3200
1200 3100 9100 3200
1300 3200 9200 3200
1400 3300 9300 3200
1300 3150 9400 3200

# 2  
Old 10-21-2015
Any attempts from your side?

---------- Post updated at 20:12 ---------- Previous update was at 20:11 ----------

Howsoever, try
Code:
awk ' 
/^FILE/         {if (FN) close (FN)
                 FN="FILE" ++CNT   
                }
                {if     ($1+0 == $1 &&
                         $2+0 == $2)  
                        {$1+=100
                         $2+=100
                        }
                 print > FN
                }
' file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-23-2015
Thanks

Thanks RUdiC it works . regarding "Any attempts from your side?".I have tried. Sorry, I am new to the scripting and I am trying to learn.

Best regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a String between start and end of a block in a file

Hi, I have a scenario where I want to display the output based on the pattern search between the start and end of a block in a file, we can have multiple start and end blocks in a file. Example give below, we need to search between the start block abc and end block def in a file, after that... (5 Replies)
Discussion started by: G.K.K
5 Replies

2. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

3. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

4. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

The difference between end number in the early row and the start number in the next

Hi Power User, I'm trying to compute this kind of text file format: file1: jakarta 100 150 jakarta 170 210 beijing 220 250 beijing 260 280 beijing 290 320 new_york 330 350 new_york 370 420 tokyo 430 470 tokyo 480 ... (2 Replies)
Discussion started by: anjas
2 Replies

7. Shell Programming and Scripting

split row into lines and insert file name

I have a directory with several hundred files. The file format is a space delimited row with an unknown number of columns: A B C D E F G ... I need to turn this format File1 A File1 B File2 A File3 A File3 B File3 C ... I can use grep to display the filename next to each row of... (2 Replies)
Discussion started by: newreverie
2 Replies

8. Shell Programming and Scripting

Append Second Row to First Row @ end in a file

Hi I want to append line 2n to 2n-1 line where n=1...LastLine in my file. eg: Actual File: Hello Everyone Welcome TO Unix I need Your help Required File: HelloEveryone WelcomeTO Unix I needYour help (5 Replies)
Discussion started by: dashing201
5 Replies

9. Shell Programming and Scripting

Split file - Include first and last row in each file.

Hi All, We have file structure as following. (Coma ';' delimiter file) Header 1;... 1;... 1;... 2;... 2;... 2;... Trailer We need to split this file as following. (for each change in first field, after header, we need to create new file with Header and Trailer line) Header... (21 Replies)
Discussion started by: meetmedude
21 Replies

10. Shell Programming and Scripting

Split a record ( in a row) and make it as new row

Hi All, The following is the scenario id name -------------- 1 William;Johnson 2 Azim;Abdul 3 Grasim . . etc.... I need the following output id name -------------- 1 William 1 Johnson 2 Azim (2 Replies)
Discussion started by: kottursamy
2 Replies
Login or Register to Ask a Question