tab separation of the file
I have a file with seq likes this
ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT
ATCACTTCTCAACCTTTTGACTAAGATCAAGTGTAATATCTATCTTTATCAGTTTAATATCTGAGATCTCCTTTATCTGAGGACAATATATTTAATGGATTTTTGGAACAGAGAGAAGGAATAGGAGCTTGTCCTGTCCACTCCATGCATTGACCTGGTATTGCAGGACCTCCAGAAACACCACCCCCTCC
ACGCATTATCCGCCTATTGGCTAAAAACAAATGTAGTATCTGTTCCTATCAGTTAAAGCATCAAATGTGGTCTCTAAGTTCAGGGAATTAAATTAATATTTGGAATTGGGAGATGGTTTGGGAGCTTGCTCTATCCTCTCCATGCCTCAGCATGTAATTGCAATGCTTTCAGGAGTGGTGCATTCCTT
It has 3 lines.
I want for each line each letter gets separated by tab and then want to store it in another file. How can i do it.
text-processing sed awk
add a comment |
I have a file with seq likes this
ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT
ATCACTTCTCAACCTTTTGACTAAGATCAAGTGTAATATCTATCTTTATCAGTTTAATATCTGAGATCTCCTTTATCTGAGGACAATATATTTAATGGATTTTTGGAACAGAGAGAAGGAATAGGAGCTTGTCCTGTCCACTCCATGCATTGACCTGGTATTGCAGGACCTCCAGAAACACCACCCCCTCC
ACGCATTATCCGCCTATTGGCTAAAAACAAATGTAGTATCTGTTCCTATCAGTTAAAGCATCAAATGTGGTCTCTAAGTTCAGGGAATTAAATTAATATTTGGAATTGGGAGATGGTTTGGGAGCTTGCTCTATCCTCTCCATGCCTCAGCATGTAATTGCAATGCTTTCAGGAGTGGTGCATTCCTT
It has 3 lines.
I want for each line each letter gets separated by tab and then want to store it in another file. How can i do it.
text-processing sed awk
2
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05
add a comment |
I have a file with seq likes this
ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT
ATCACTTCTCAACCTTTTGACTAAGATCAAGTGTAATATCTATCTTTATCAGTTTAATATCTGAGATCTCCTTTATCTGAGGACAATATATTTAATGGATTTTTGGAACAGAGAGAAGGAATAGGAGCTTGTCCTGTCCACTCCATGCATTGACCTGGTATTGCAGGACCTCCAGAAACACCACCCCCTCC
ACGCATTATCCGCCTATTGGCTAAAAACAAATGTAGTATCTGTTCCTATCAGTTAAAGCATCAAATGTGGTCTCTAAGTTCAGGGAATTAAATTAATATTTGGAATTGGGAGATGGTTTGGGAGCTTGCTCTATCCTCTCCATGCCTCAGCATGTAATTGCAATGCTTTCAGGAGTGGTGCATTCCTT
It has 3 lines.
I want for each line each letter gets separated by tab and then want to store it in another file. How can i do it.
text-processing sed awk
I have a file with seq likes this
ATCGTTTCTCAGCCTTTTGGCAAGACCAAGTGTAGTATCTGTTCTTATCAGATATTGGTATCTGCAGGCACTCCTGGAACCAAT
ATCACTTCTCAACCTTTTGACTAAGATCAAGTGTAATATCTATCTTTATCAGTTTAATATCTGAGATCTCCTTTATCTGAGGACAATATATTTAATGGATTTTTGGAACAGAGAGAAGGAATAGGAGCTTGTCCTGTCCACTCCATGCATTGACCTGGTATTGCAGGACCTCCAGAAACACCACCCCCTCC
ACGCATTATCCGCCTATTGGCTAAAAACAAATGTAGTATCTGTTCCTATCAGTTAAAGCATCAAATGTGGTCTCTAAGTTCAGGGAATTAAATTAATATTTGGAATTGGGAGATGGTTTGGGAGCTTGCTCTATCCTCTCCATGCCTCAGCATGTAATTGCAATGCTTTCAGGAGTGGTGCATTCCTT
It has 3 lines.
I want for each line each letter gets separated by tab and then want to store it in another file. How can i do it.
text-processing sed awk
text-processing sed awk
edited 1 hour ago
Rui F Ribeiro
41.3k1481140
41.3k1481140
asked Dec 17 '14 at 22:38
user3138373user3138373
89041630
89041630
2
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05
add a comment |
2
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05
2
2
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05
add a comment |
4 Answers
4
active
oldest
votes
If I have understood your intention correctly then this does it:
sed -e 's/./&t/g' -e $'s/t$//' file
The second replacement deletes the tab at the end of the line.
add a comment |
Try doing this using perl:
perl -ne 'print join "t", split //' file > new_file
If you like golf:perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
add a comment |
In awk
:
awk -F '' -vOFS='t' '{$1=$1}1' file > new_file
Borrowed the idiom {$1=$1}1
from an answer to one of your other questions.
This sets the field separator to nothing (-F ''
), which means that each record is read character-by-character. The output field separator is set to a TAB character (-vOFS='t'
) and the idiom {$1=$1}1
is (as far as I can tell) a no-op that has the side effect of causing awk
to insert the OFS
between every two fields before printing them all.
pretty good. not everybody breaks it down by arguments. someday I'll learn how to useawk
probably - and I'll need it broken down that way I expect. thanks.
– mikeserv
Dec 18 '14 at 4:52
1
@mikeserv Thanks. I have promised myself to learn properawk
one day, too :)
– Joseph R.
Dec 18 '14 at 4:53
I wonder if that{$1=$1}1
thing is anything likesed
'ss/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.
– mikeserv
Dec 18 '14 at 4:56
1
@mikeserv Probably not. As far as I can tell,$1=$1
doesn't do anything but tricksawk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The1
at the end is to simply return a "true" value and causeawk
to print the current record by default.
– Joseph R.
Dec 18 '14 at 4:58
add a comment |
I think you should give fold
a go:
tr \n \r <infile | fold -w1 | tr 'rn' 'nt' >outfile
I preprocess fold
's input w/ tr
by replacing the instream n
ewline characters w/ r
eturns. fold
is printing a n
ewline character for every column in input - each of your capital letters - but it resets its counter on r
eturns and so when tr
does the final post-processing and converts fold
's n
ewlines to t
abs there are no extra t
ab characters in output. The output is three lines with a t
ab character following each character but the last on each line.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f174755%2ftab-separation-of-the-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
If I have understood your intention correctly then this does it:
sed -e 's/./&t/g' -e $'s/t$//' file
The second replacement deletes the tab at the end of the line.
add a comment |
If I have understood your intention correctly then this does it:
sed -e 's/./&t/g' -e $'s/t$//' file
The second replacement deletes the tab at the end of the line.
add a comment |
If I have understood your intention correctly then this does it:
sed -e 's/./&t/g' -e $'s/t$//' file
The second replacement deletes the tab at the end of the line.
If I have understood your intention correctly then this does it:
sed -e 's/./&t/g' -e $'s/t$//' file
The second replacement deletes the tab at the end of the line.
edited Dec 18 '14 at 0:40
answered Dec 17 '14 at 22:41
Hauke LagingHauke Laging
57.2k1287135
57.2k1287135
add a comment |
add a comment |
Try doing this using perl:
perl -ne 'print join "t", split //' file > new_file
If you like golf:perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
add a comment |
Try doing this using perl:
perl -ne 'print join "t", split //' file > new_file
If you like golf:perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
add a comment |
Try doing this using perl:
perl -ne 'print join "t", split //' file > new_file
Try doing this using perl:
perl -ne 'print join "t", split //' file > new_file
edited Dec 17 '14 at 22:48
answered Dec 17 '14 at 22:41
Gilles QuenotGilles Quenot
16.3k14053
16.3k14053
If you like golf:perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
add a comment |
If you like golf:perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
If you like golf:
perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
If you like golf:
perl -ne '$,="t";print split//' file > new_file
– Joseph R.
Dec 18 '14 at 5:00
add a comment |
In awk
:
awk -F '' -vOFS='t' '{$1=$1}1' file > new_file
Borrowed the idiom {$1=$1}1
from an answer to one of your other questions.
This sets the field separator to nothing (-F ''
), which means that each record is read character-by-character. The output field separator is set to a TAB character (-vOFS='t'
) and the idiom {$1=$1}1
is (as far as I can tell) a no-op that has the side effect of causing awk
to insert the OFS
between every two fields before printing them all.
pretty good. not everybody breaks it down by arguments. someday I'll learn how to useawk
probably - and I'll need it broken down that way I expect. thanks.
– mikeserv
Dec 18 '14 at 4:52
1
@mikeserv Thanks. I have promised myself to learn properawk
one day, too :)
– Joseph R.
Dec 18 '14 at 4:53
I wonder if that{$1=$1}1
thing is anything likesed
'ss/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.
– mikeserv
Dec 18 '14 at 4:56
1
@mikeserv Probably not. As far as I can tell,$1=$1
doesn't do anything but tricksawk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The1
at the end is to simply return a "true" value and causeawk
to print the current record by default.
– Joseph R.
Dec 18 '14 at 4:58
add a comment |
In awk
:
awk -F '' -vOFS='t' '{$1=$1}1' file > new_file
Borrowed the idiom {$1=$1}1
from an answer to one of your other questions.
This sets the field separator to nothing (-F ''
), which means that each record is read character-by-character. The output field separator is set to a TAB character (-vOFS='t'
) and the idiom {$1=$1}1
is (as far as I can tell) a no-op that has the side effect of causing awk
to insert the OFS
between every two fields before printing them all.
pretty good. not everybody breaks it down by arguments. someday I'll learn how to useawk
probably - and I'll need it broken down that way I expect. thanks.
– mikeserv
Dec 18 '14 at 4:52
1
@mikeserv Thanks. I have promised myself to learn properawk
one day, too :)
– Joseph R.
Dec 18 '14 at 4:53
I wonder if that{$1=$1}1
thing is anything likesed
'ss/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.
– mikeserv
Dec 18 '14 at 4:56
1
@mikeserv Probably not. As far as I can tell,$1=$1
doesn't do anything but tricksawk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The1
at the end is to simply return a "true" value and causeawk
to print the current record by default.
– Joseph R.
Dec 18 '14 at 4:58
add a comment |
In awk
:
awk -F '' -vOFS='t' '{$1=$1}1' file > new_file
Borrowed the idiom {$1=$1}1
from an answer to one of your other questions.
This sets the field separator to nothing (-F ''
), which means that each record is read character-by-character. The output field separator is set to a TAB character (-vOFS='t'
) and the idiom {$1=$1}1
is (as far as I can tell) a no-op that has the side effect of causing awk
to insert the OFS
between every two fields before printing them all.
In awk
:
awk -F '' -vOFS='t' '{$1=$1}1' file > new_file
Borrowed the idiom {$1=$1}1
from an answer to one of your other questions.
This sets the field separator to nothing (-F ''
), which means that each record is read character-by-character. The output field separator is set to a TAB character (-vOFS='t'
) and the idiom {$1=$1}1
is (as far as I can tell) a no-op that has the side effect of causing awk
to insert the OFS
between every two fields before printing them all.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Dec 18 '14 at 4:49
Joseph R.Joseph R.
28.6k375116
28.6k375116
pretty good. not everybody breaks it down by arguments. someday I'll learn how to useawk
probably - and I'll need it broken down that way I expect. thanks.
– mikeserv
Dec 18 '14 at 4:52
1
@mikeserv Thanks. I have promised myself to learn properawk
one day, too :)
– Joseph R.
Dec 18 '14 at 4:53
I wonder if that{$1=$1}1
thing is anything likesed
'ss/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.
– mikeserv
Dec 18 '14 at 4:56
1
@mikeserv Probably not. As far as I can tell,$1=$1
doesn't do anything but tricksawk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The1
at the end is to simply return a "true" value and causeawk
to print the current record by default.
– Joseph R.
Dec 18 '14 at 4:58
add a comment |
pretty good. not everybody breaks it down by arguments. someday I'll learn how to useawk
probably - and I'll need it broken down that way I expect. thanks.
– mikeserv
Dec 18 '14 at 4:52
1
@mikeserv Thanks. I have promised myself to learn properawk
one day, too :)
– Joseph R.
Dec 18 '14 at 4:53
I wonder if that{$1=$1}1
thing is anything likesed
'ss/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.
– mikeserv
Dec 18 '14 at 4:56
1
@mikeserv Probably not. As far as I can tell,$1=$1
doesn't do anything but tricksawk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The1
at the end is to simply return a "true" value and causeawk
to print the current record by default.
– Joseph R.
Dec 18 '14 at 4:58
pretty good. not everybody breaks it down by arguments. someday I'll learn how to use
awk
probably - and I'll need it broken down that way I expect. thanks.– mikeserv
Dec 18 '14 at 4:52
pretty good. not everybody breaks it down by arguments. someday I'll learn how to use
awk
probably - and I'll need it broken down that way I expect. thanks.– mikeserv
Dec 18 '14 at 4:52
1
1
@mikeserv Thanks. I have promised myself to learn proper
awk
one day, too :)– Joseph R.
Dec 18 '14 at 4:53
@mikeserv Thanks. I have promised myself to learn proper
awk
one day, too :)– Joseph R.
Dec 18 '14 at 4:53
I wonder if that
{$1=$1}1
thing is anything like sed
's s/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.– mikeserv
Dec 18 '14 at 4:56
I wonder if that
{$1=$1}1
thing is anything like sed
's s/.{0,1}/ /g
? You know - matching the null field between the strings? That's pretty cool, anyway.– mikeserv
Dec 18 '14 at 4:56
1
1
@mikeserv Probably not. As far as I can tell,
$1=$1
doesn't do anything but tricks awk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The 1
at the end is to simply return a "true" value and cause awk
to print the current record by default.– Joseph R.
Dec 18 '14 at 4:58
@mikeserv Probably not. As far as I can tell,
$1=$1
doesn't do anything but tricks awk
into thinking the first field has been re-assigned so that it knows to insert the OFS between adjacent fields. The 1
at the end is to simply return a "true" value and cause awk
to print the current record by default.– Joseph R.
Dec 18 '14 at 4:58
add a comment |
I think you should give fold
a go:
tr \n \r <infile | fold -w1 | tr 'rn' 'nt' >outfile
I preprocess fold
's input w/ tr
by replacing the instream n
ewline characters w/ r
eturns. fold
is printing a n
ewline character for every column in input - each of your capital letters - but it resets its counter on r
eturns and so when tr
does the final post-processing and converts fold
's n
ewlines to t
abs there are no extra t
ab characters in output. The output is three lines with a t
ab character following each character but the last on each line.
add a comment |
I think you should give fold
a go:
tr \n \r <infile | fold -w1 | tr 'rn' 'nt' >outfile
I preprocess fold
's input w/ tr
by replacing the instream n
ewline characters w/ r
eturns. fold
is printing a n
ewline character for every column in input - each of your capital letters - but it resets its counter on r
eturns and so when tr
does the final post-processing and converts fold
's n
ewlines to t
abs there are no extra t
ab characters in output. The output is three lines with a t
ab character following each character but the last on each line.
add a comment |
I think you should give fold
a go:
tr \n \r <infile | fold -w1 | tr 'rn' 'nt' >outfile
I preprocess fold
's input w/ tr
by replacing the instream n
ewline characters w/ r
eturns. fold
is printing a n
ewline character for every column in input - each of your capital letters - but it resets its counter on r
eturns and so when tr
does the final post-processing and converts fold
's n
ewlines to t
abs there are no extra t
ab characters in output. The output is three lines with a t
ab character following each character but the last on each line.
I think you should give fold
a go:
tr \n \r <infile | fold -w1 | tr 'rn' 'nt' >outfile
I preprocess fold
's input w/ tr
by replacing the instream n
ewline characters w/ r
eturns. fold
is printing a n
ewline character for every column in input - each of your capital letters - but it resets its counter on r
eturns and so when tr
does the final post-processing and converts fold
's n
ewlines to t
abs there are no extra t
ab characters in output. The output is three lines with a t
ab character following each character but the last on each line.
answered Dec 18 '14 at 3:41
mikeservmikeserv
45.8k668160
45.8k668160
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f174755%2ftab-separation-of-the-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
With such questions you should always give an example for the expected output.
– Hauke Laging
Dec 17 '14 at 22:41
It's a DNA sequence... How long is the strand? ie you should split tabs at the end of the chain. Add more info as Hauke states.
– eyoung100
Dec 17 '14 at 23:05