PDA

View Full Version : How to: Split one column into two




LouiseT
Apr 11, 2013, 12:39 AM
Hi everyone
I have been trying to split content of one column into two. Sounds simple but I have not gotten it to work.
My file looks like this:
chr17 65505 65506 (#Coding_GN)@(#Coding_GN)
chr4 68144 68145 0!overlap@ (#Coding_GN_ensemble)
chr4 68199 68200 0!overlap@ (#Coding_GN_ensemble)

And I would like to split column 4 by @ so I get:

hr17 65505 65506 (#Coding_GN) (#Coding_GN)
chr4 68144 68145 0!overlap (#Coding_GN_ensemble)
chr4 68199 68200 0!overlap (#Coding_GN_ensemble)

Anyone know of a awk, sed or other UNIX inbuilt command/function which can do this?

Thanks



Flantec
Apr 11, 2013, 01:05 AM
Hi everyone
I have been trying to split content of one column into two. Sounds simple but I have not gotten it to work.
My file looks like this:
chr17 65505 65506 (#Coding_GN)@(#Coding_GN)
chr4 68144 68145 0!overlap@ (#Coding_GN_ensemble)
chr4 68199 68200 0!overlap@ (#Coding_GN_ensemble)

And I would like to split column 4 by @ so I get:

hr17 65505 65506 (#Coding_GN) (#Coding_GN)
chr4 68144 68145 0!overlap (#Coding_GN_ensemble)
chr4 68199 68200 0!overlap (#Coding_GN_ensemble)

Anyone know of a awk, sed or other UNIX inbuilt command/function which can do this?

Thanks

It does not appear that you are splitting column 4, but are just removing the "@" from it. Assuming that I am understanding this correctly, use sed to just remove the "@" symbols.

cat somefile | sed 's/@//g'

LouiseT
Apr 11, 2013, 01:58 AM
No, I can see that does not look like I split the 4th column. That was an seperator effect that glided.
I would like 5 column in output.
ex (set op a little different ($ = column):
input:
$1= chr17
$2= 65505
$3= 65506
$4= (#Coding_GN)@(#Coding_GN)

Output:
$1 = chr17
$2 = 65505
$3 = 65506
$4 = (#Coding_GN)
$5 = (#Coding_GN)

chown33
Apr 11, 2013, 12:13 PM
Use the 'tr' command to translate '@' to ' ' (space).

You can also use 'tr' to squeeze multiple spaces into a single space.

See 'man tr'.

If you have a problem or it doesn't work, post the command that doesn't work, then describe what happens and what you expected to happen.