How to: Split one column into two

Discussion in 'OS X Mountain Lion (10.8)' started by LouiseT, Apr 10, 2013.

  1. LouiseT
    Expand Collapse
    macrumors newbie

    Feb 11, 2013
    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?

  2. Flantec
    Expand Collapse
    macrumors newbie

    May 31, 2009
    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'
  3. LouiseT
    Expand Collapse
    thread starter macrumors newbie

    Feb 11, 2013
    I would like 5 columns in output

    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):
    $1= chr17
    $2= 65505
    $3= 65506
    $4= (#Coding_GN)@(#Coding_GN)

    $1 = chr17
    $2 = 65505
    $3 = 65506
    $4 = (#Coding_GN)
    $5 = (#Coding_GN)
  4. chown33
    Expand Collapse
    macrumors 604

    Aug 9, 2009
    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.

Share This Page