splitting a column using awk
I have a file like shown below. The 9th column has values joined by **.
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342**0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481**0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955**0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026**0.00352844797952 +
I want to have an output where I can have the 2 values as sep columns. How can I do this in awk.
This is the output I want. Showing the first line of the output:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
awk
add a comment |
I have a file like shown below. The 9th column has values joined by **.
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342**0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481**0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955**0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026**0.00352844797952 +
I want to have an output where I can have the 2 values as sep columns. How can I do this in awk.
This is the output I want. Showing the first line of the output:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
awk
2
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08
add a comment |
I have a file like shown below. The 9th column has values joined by **.
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342**0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481**0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955**0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026**0.00352844797952 +
I want to have an output where I can have the 2 values as sep columns. How can I do this in awk.
This is the output I want. Showing the first line of the output:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
awk
I have a file like shown below. The 9th column has values joined by **.
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342**0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481**0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955**0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026**0.00352844797952 +
I want to have an output where I can have the 2 values as sep columns. How can I do this in awk.
This is the output I want. Showing the first line of the output:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
awk
awk
edited Sep 23 '14 at 13:49
Braiam
23.2k1976139
23.2k1976139
asked Sep 22 '14 at 19:16
user3138373user3138373
87041630
87041630
2
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08
add a comment |
2
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08
2
2
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08
add a comment |
5 Answers
5
active
oldest
votes
No idea why people are using cat to pipe the file into awk, and the tr answer only translates one character into another, so any *
is converted to a space
.
Simple awk solution
awk -F"**" '$1=$1' OFS="t" file
For tab between all fields
awk 'sub(/**/," "){$1=$1}1' OFS="t" file
And one more
awk 'gsub(/(*| )+/,"t")' file
Sed command
sed 's/[* ]+/t/g' file
tr command
tr -s '* ' 't' < file
add a comment |
Does it have to be awk? Why not cat file | tr '**' ' '
Just replacing the **'s with three spaces
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How aboutcat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
With a single space I'd use a gsub as followscat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
I don't thinktr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two*
s with three spaces
– iruvar
Sep 22 '14 at 20:00
|
show 4 more comments
cat text.txt |awk '{ split($9,a , "**"); printf("%st%st%st%st%st%st%st%st%st%st%sn",$1,$2,$3,$4,$5,$6,$7,$8, a[1], a[2],$10); }'
Output is:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481 0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955 0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026 0.00352844797952 +
add a comment |
Replacement of one substring by another is clearly work for sed. If you want it in awk, I assume you wish to do some additional processing by awk. To do so, you should just use the regex field separator:
awk -F'(**| )' '{.you code here.; print $10}'
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using''
as column separator do what OP wants in any way, also it won't separate based on two*
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try-F'(*| )+'
as this would do what you think your current code does.
– user78605
Sep 25 '14 at 10:56
|
show 1 more comment
awk -F'**' 'BEGIN{OFS=" ";} {print $1,$2}' file
use '**' as separator and set three whitespaces as output separator
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%2f156919%2fsplitting-a-column-using-awk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
No idea why people are using cat to pipe the file into awk, and the tr answer only translates one character into another, so any *
is converted to a space
.
Simple awk solution
awk -F"**" '$1=$1' OFS="t" file
For tab between all fields
awk 'sub(/**/," "){$1=$1}1' OFS="t" file
And one more
awk 'gsub(/(*| )+/,"t")' file
Sed command
sed 's/[* ]+/t/g' file
tr command
tr -s '* ' 't' < file
add a comment |
No idea why people are using cat to pipe the file into awk, and the tr answer only translates one character into another, so any *
is converted to a space
.
Simple awk solution
awk -F"**" '$1=$1' OFS="t" file
For tab between all fields
awk 'sub(/**/," "){$1=$1}1' OFS="t" file
And one more
awk 'gsub(/(*| )+/,"t")' file
Sed command
sed 's/[* ]+/t/g' file
tr command
tr -s '* ' 't' < file
add a comment |
No idea why people are using cat to pipe the file into awk, and the tr answer only translates one character into another, so any *
is converted to a space
.
Simple awk solution
awk -F"**" '$1=$1' OFS="t" file
For tab between all fields
awk 'sub(/**/," "){$1=$1}1' OFS="t" file
And one more
awk 'gsub(/(*| )+/,"t")' file
Sed command
sed 's/[* ]+/t/g' file
tr command
tr -s '* ' 't' < file
No idea why people are using cat to pipe the file into awk, and the tr answer only translates one character into another, so any *
is converted to a space
.
Simple awk solution
awk -F"**" '$1=$1' OFS="t" file
For tab between all fields
awk 'sub(/**/," "){$1=$1}1' OFS="t" file
And one more
awk 'gsub(/(*| )+/,"t")' file
Sed command
sed 's/[* ]+/t/g' file
tr command
tr -s '* ' 't' < file
edited Sep 23 '14 at 13:49
answered Sep 23 '14 at 8:53
user78605
add a comment |
add a comment |
Does it have to be awk? Why not cat file | tr '**' ' '
Just replacing the **'s with three spaces
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How aboutcat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
With a single space I'd use a gsub as followscat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
I don't thinktr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two*
s with three spaces
– iruvar
Sep 22 '14 at 20:00
|
show 4 more comments
Does it have to be awk? Why not cat file | tr '**' ' '
Just replacing the **'s with three spaces
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How aboutcat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
With a single space I'd use a gsub as followscat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
I don't thinktr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two*
s with three spaces
– iruvar
Sep 22 '14 at 20:00
|
show 4 more comments
Does it have to be awk? Why not cat file | tr '**' ' '
Just replacing the **'s with three spaces
Does it have to be awk? Why not cat file | tr '**' ' '
Just replacing the **'s with three spaces
answered Sep 22 '14 at 19:20
kevino_17kevino_17
1091
1091
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How aboutcat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
With a single space I'd use a gsub as followscat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
I don't thinktr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two*
s with three spaces
– iruvar
Sep 22 '14 at 20:00
|
show 4 more comments
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How aboutcat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
With a single space I'd use a gsub as followscat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
I don't thinktr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two*
s with three spaces
– iruvar
Sep 22 '14 at 20:00
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
tr '**' 't' works too. Wanted it as tab separated. Does 3 spaces equivalent to a tab?. I want to see how awk would do this?
– user3138373
Sep 22 '14 at 19:23
How about
cat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
How about
cat file | awk -F "**" '{print $1 "t" $2}'
– kevino_17
Sep 22 '14 at 19:28
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
Ahh I didn't thought of field separator FS. You just separated the fields on **. The file was already tab separated so everything came out ok. Also let's say columns were separated by single space and I want the output as tab separated. What should be done. Can we specify 2 FS? nICE SOLUTION tHANKS!!!
– user3138373
Sep 22 '14 at 19:32
1
1
With a single space I'd use a gsub as follows
cat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
With a single space I'd use a gsub as follows
cat file| awk '{gsub("[**| ]","t"); print $0 }'
– kevino_17
Sep 22 '14 at 19:45
4
4
I don't think
tr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two *
s with three spaces– iruvar
Sep 22 '14 at 20:00
I don't think
tr
does what you think it does. It transliterates one character at a time so I am not sure how you could get it to replace two *
s with three spaces– iruvar
Sep 22 '14 at 20:00
|
show 4 more comments
cat text.txt |awk '{ split($9,a , "**"); printf("%st%st%st%st%st%st%st%st%st%st%sn",$1,$2,$3,$4,$5,$6,$7,$8, a[1], a[2],$10); }'
Output is:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481 0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955 0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026 0.00352844797952 +
add a comment |
cat text.txt |awk '{ split($9,a , "**"); printf("%st%st%st%st%st%st%st%st%st%st%sn",$1,$2,$3,$4,$5,$6,$7,$8, a[1], a[2],$10); }'
Output is:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481 0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955 0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026 0.00352844797952 +
add a comment |
cat text.txt |awk '{ split($9,a , "**"); printf("%st%st%st%st%st%st%st%st%st%st%sn",$1,$2,$3,$4,$5,$6,$7,$8, a[1], a[2],$10); }'
Output is:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481 0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955 0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026 0.00352844797952 +
cat text.txt |awk '{ split($9,a , "**"); printf("%st%st%st%st%st%st%st%st%st%st%sn",$1,$2,$3,$4,$5,$6,$7,$8, a[1], a[2],$10); }'
Output is:
chrXV 234346 234546 snR81 + SNR81 chrXV 234357 0.0003015891774815342 0.131826816475 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234385 0.0002208827994288481 0.0118547789578 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234396 0.0001799579220002955 0.00583993781634 +
chrXV 234346 234546 snR81 + SNR81 chrXV 234410 0.003451057940295026 0.00352844797952 +
answered Sep 22 '14 at 20:19
PersianGulfPersianGulf
6,93543461
6,93543461
add a comment |
add a comment |
Replacement of one substring by another is clearly work for sed. If you want it in awk, I assume you wish to do some additional processing by awk. To do so, you should just use the regex field separator:
awk -F'(**| )' '{.you code here.; print $10}'
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using''
as column separator do what OP wants in any way, also it won't separate based on two*
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try-F'(*| )+'
as this would do what you think your current code does.
– user78605
Sep 25 '14 at 10:56
|
show 1 more comment
Replacement of one substring by another is clearly work for sed. If you want it in awk, I assume you wish to do some additional processing by awk. To do so, you should just use the regex field separator:
awk -F'(**| )' '{.you code here.; print $10}'
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using''
as column separator do what OP wants in any way, also it won't separate based on two*
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try-F'(*| )+'
as this would do what you think your current code does.
– user78605
Sep 25 '14 at 10:56
|
show 1 more comment
Replacement of one substring by another is clearly work for sed. If you want it in awk, I assume you wish to do some additional processing by awk. To do so, you should just use the regex field separator:
awk -F'(**| )' '{.you code here.; print $10}'
Replacement of one substring by another is clearly work for sed. If you want it in awk, I assume you wish to do some additional processing by awk. To do so, you should just use the regex field separator:
awk -F'(**| )' '{.you code here.; print $10}'
edited Sep 25 '14 at 12:46
answered Sep 23 '14 at 9:12
gena2xgena2x
1,836618
1,836618
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using''
as column separator do what OP wants in any way, also it won't separate based on two*
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try-F'(*| )+'
as this would do what you think your current code does.
– user78605
Sep 25 '14 at 10:56
|
show 1 more comment
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using''
as column separator do what OP wants in any way, also it won't separate based on two*
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try-F'(*| )+'
as this would do what you think your current code does.
– user78605
Sep 25 '14 at 10:56
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
That regex is awful and wont work. -1 for the fact that you also have answered as though you understand what you are doing.
– user78605
Sep 23 '14 at 10:27
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
Could you please explain why regex is "awful" and also what is the reason it "wont work". I have no idea. I tested it before posting and it does work perfectly.
– gena2x
Sep 24 '14 at 18:25
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
What do you think it does ?
– user78605
Sep 25 '14 at 7:23
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
It uses either ' **' or ' ' as column separator - something that nobody else suggested in other answers. And leaves the exact way of output for author.
– gena2x
Sep 25 '14 at 10:27
I know what you were trying to do, how does using
''
as column separator do what OP wants in any way, also it won't separate based on two *
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try -F'(*| )+'
as this would do what you think your current code does.– user78605
Sep 25 '14 at 10:56
I know what you were trying to do, how does using
''
as column separator do what OP wants in any way, also it won't separate based on two *
as the there is a space before and after it in the regex. Honestly i don't even know why i am explaining this to you as i don't understand how after looking at your code you still don't see how it is completely wrong in every way. Try -F'(*| )+'
as this would do what you think your current code does.– user78605
Sep 25 '14 at 10:56
|
show 1 more comment
awk -F'**' 'BEGIN{OFS=" ";} {print $1,$2}' file
use '**' as separator and set three whitespaces as output separator
add a comment |
awk -F'**' 'BEGIN{OFS=" ";} {print $1,$2}' file
use '**' as separator and set three whitespaces as output separator
add a comment |
awk -F'**' 'BEGIN{OFS=" ";} {print $1,$2}' file
use '**' as separator and set three whitespaces as output separator
awk -F'**' 'BEGIN{OFS=" ";} {print $1,$2}' file
use '**' as separator and set three whitespaces as output separator
answered Jan 8 at 17:23
Emilio GalarragaEmilio Galarraga
50929
50929
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%2f156919%2fsplitting-a-column-using-awk%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
Please always specify your column separator. Since this is a gff file, I assume it's tab separated but people won't know this unless you state it.
– terdon♦
Sep 23 '14 at 9:08