Help with split a list of records into each line with 200 coordinate at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with split a list of records into each line with 200 coordinate at a time
# 1  
Old 08-27-2018
Help with split a list of records into each line with 200 coordinate at a time

Input File:
Code:
E	3359799	3360148	350	X
D	3471287	3471607	321	X
E	3359799	3360740	942	X
E	4359790	4360039	250	X
.
.
.

Desired Output File:
Code:
E	3359799	3359998	200	X
E	3359999	3360148	150	X
D	3471287	3471486	200	X
D	3471487	3471607	121	X
E	3359799	3359998	200	X
E	3359999	3360198	200	X
E	3360199	3360398	200	X
E	3360399	3360598	200	X
E	3360599	3360740	142	X
E	4359790	4359989	200	X
E	4359990	4360039	50	X
.
.
.

My input file have 5 columns data.
Column 1 is Sample ID;
Column 2 is Start;
Column 3 is End;
Column 4 is Distance (End-Start+1);
Column 5 is Target;

Anyone know how to using awk, perl or any programming language that can split a list of record in Input File with 200 coordinate at a time?
Every line at Input File is represents a record. I hope to split it with 200 coordinate at a time.

Thanks for any advice.
# 2  
Old 08-27-2018
Whatever "with 200 coordinate at a time" means, how about


Code:
awk '{TMP = $4; while (TMP > 200) {$3 = $2 + 200 - 1; $4 = 200; print; $2 += 200; TMP -= 200} $3 += TMP; $4 = TMP; print} ' file
E 3359799 3359998 200 X
E 3359999 3360148 150 X
D 3471287 3471486 200 X
D 3471487 3471607 121 X
E 3359799 3359998 200 X
E 3359999 3360198 200 X
E 3360199 3360398 200 X
E 3360399 3360598 200 X
E 3360599 3360740 142 X
E 4359790 4359989 200 X
 E 4359990 4360039 50 X


EDIT: Or, to stay with your nomenclature, try

Code:
awk '{TMP = $4; while (TMP > COORD) {$3 = $2 + COORD - 1; $4 = COORD; print; $2 += COORD; TMP -= COORD} $3 += TMP; $4 = TMP; print} ' COORD=200 file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split records

Hi I have a file $cat test a,1;2;3 b,4;5;6;7 c,8;9 I want to split each record to multiple based on semicolon in 2nd field. i.e a,1 a,2 a,3 b,4 b,5 (3 Replies)
Discussion started by: Shivdatta
3 Replies

2. Shell Programming and Scripting

Sorting with list, - 2 lists next to 200

Hi I was wondering if anyone knew the best way to have files displayed by list so that they were in numerical order? the problem I am having is I am using the ls and the head command to sort a group of 500 files into manageable 133 file bunches and transfer them to another directory were they will... (4 Replies)
Discussion started by: Paul Walker
4 Replies

3. Shell Programming and Scripting

Split Records

I have a flat file with 2 columns Id,loc 1,nj:ny:pa 2,pa 3,ca:tx:fl:nj Second colum data is seperated by semi colon and can i have many locations for one id Output i need is 1,nj 1,ny 1,pa 1,pa 3,ca 3,tx 3,fl (1 Reply)
Discussion started by: traininfa
1 Replies

4. Shell Programming and Scripting

Split records into multiple records

Hi All, I am trying to split a record into multiple records based on a value. Input.txt "A",1,0,10 "B",2,0,10,15,20 "C",3,11,14,16,19,21,23 "D",1,0,5 My desired output is: "A",1,0,10 "B",2,0,10 "B",2,15,20 "C",3,11,14 "C",3,16,19 "C",3,21,23 (4 Replies)
Discussion started by: kmsekhar
4 Replies

5. Shell Programming and Scripting

split records into different files

Hi All, I want my file to be split based on value of 'N' (passed as argument). If value of 'N' is '2' then 4 new files will be generated from the below source file and the o/p file shoud look like File_$num , where num will be incremental. Source file: 1 2 3 4 5 O/p Files: ... (6 Replies)
Discussion started by: HemaV
6 Replies

6. Shell Programming and Scripting

Split a single record to multiple records & add folder name to each line

Hi Gurus, I need to cut single record in the file(asdf) to multile records based on the number of bytes..(44 characters). So every record will have 44 characters. All the records should be in the same file..to each of these lines I need to add the folder(<date>) name. I have a dir. in which... (20 Replies)
Discussion started by: ram2581
20 Replies

7. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

8. UNIX for Dummies Questions & Answers

Split 200.000 files into different subfolders

Dear UNIX-Community, can help me doing 2 things in Debian 5.0? 1.) Create 100 folders Format: ./0/0, ./0/1, ./0/2, ...,./0/9, ./1/0/, ..., ./9/9 2.) Move over 200.000 files into the subdirectories according to their last digits. 12398123.dat -> ./3/2/12398123.dat 48161.dat ->... (2 Replies)
Discussion started by: diadas
2 Replies

9. Shell Programming and Scripting

List UID's between 100 and 200

If i wanted to list all users who have a UID between 100 and 200 which command would i use? (1 Reply)
Discussion started by: warlock129
1 Replies
Login or Register to Ask a Question