Splitting file content into the files [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
This question already has an answer here:
splitting file based on values in specific column
1 answer
Splitting file content into other files based on parsed parameter value in file [duplicate]
1 answer
Extract data from a file and place in different files based on1 column value
5 answers
I have a big huge file e.g
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
I need help in splitting the file in multiple files by grouping the first column values e.g
File1.txt
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
file 3.txt
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
shell awk
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Apr 20 at 12:04
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
-1
down vote
favorite
This question already has an answer here:
splitting file based on values in specific column
1 answer
Splitting file content into other files based on parsed parameter value in file [duplicate]
1 answer
Extract data from a file and place in different files based on1 column value
5 answers
I have a big huge file e.g
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
I need help in splitting the file in multiple files by grouping the first column values e.g
File1.txt
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
file 3.txt
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
shell awk
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Apr 20 at 12:04
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
This question already has an answer here:
splitting file based on values in specific column
1 answer
Splitting file content into other files based on parsed parameter value in file [duplicate]
1 answer
Extract data from a file and place in different files based on1 column value
5 answers
I have a big huge file e.g
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
I need help in splitting the file in multiple files by grouping the first column values e.g
File1.txt
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
file 3.txt
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
shell awk
This question already has an answer here:
splitting file based on values in specific column
1 answer
Splitting file content into other files based on parsed parameter value in file [duplicate]
1 answer
Extract data from a file and place in different files based on1 column value
5 answers
I have a big huge file e.g
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
I need help in splitting the file in multiple files by grouping the first column values e.g
File1.txt
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
file 3.txt
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
This question already has an answer here:
splitting file based on values in specific column
1 answer
Splitting file content into other files based on parsed parameter value in file [duplicate]
1 answer
Extract data from a file and place in different files based on1 column value
5 answers
shell awk
edited Apr 20 at 11:59
Archemar
18.9k93366
18.9k93366
asked Apr 20 at 11:44
sidd
1
1
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Apr 20 at 12:04
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Apr 20 at 12:04
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Awk solution:
awk ' print > ("file" substr($1, 4) ".txt") ' file
substr($1, 4)- extract substring from the 1st field value$1starting from position4
Viewing results:
$ head file[0-9]*.txt
==> file1.txt <==
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
==> file3.txt <==
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
==> file4.txt <==
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
==> file6.txt <==
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Awk solution:
awk ' print > ("file" substr($1, 4) ".txt") ' file
substr($1, 4)- extract substring from the 1st field value$1starting from position4
Viewing results:
$ head file[0-9]*.txt
==> file1.txt <==
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
==> file3.txt <==
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
==> file4.txt <==
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
==> file6.txt <==
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
add a comment |Â
up vote
2
down vote
Awk solution:
awk ' print > ("file" substr($1, 4) ".txt") ' file
substr($1, 4)- extract substring from the 1st field value$1starting from position4
Viewing results:
$ head file[0-9]*.txt
==> file1.txt <==
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
==> file3.txt <==
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
==> file4.txt <==
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
==> file6.txt <==
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Awk solution:
awk ' print > ("file" substr($1, 4) ".txt") ' file
substr($1, 4)- extract substring from the 1st field value$1starting from position4
Viewing results:
$ head file[0-9]*.txt
==> file1.txt <==
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
==> file3.txt <==
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
==> file4.txt <==
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
==> file6.txt <==
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
Awk solution:
awk ' print > ("file" substr($1, 4) ".txt") ' file
substr($1, 4)- extract substring from the 1st field value$1starting from position4
Viewing results:
$ head file[0-9]*.txt
==> file1.txt <==
chr1 1 G 300
chr1 2 A 500
chr1 3 C 200
==> file3.txt <==
chr3 1 G 300
chr3 2 A 500
chr3 3 C 200
chr3 1 T 35
chr3 2 G 400
==> file4.txt <==
chr4 1 T 35
chr4 2 G 400
chr4 3 C 435
==> file6.txt <==
chr6 3 C 435
chr6 4 A 223
chr6 5 T 400
chr6 6 G 300
answered Apr 20 at 12:01
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â