1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How to: Split one column into two

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

  1. macrumors newbie

    #1
    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
     
  2. macrumors newbie

    #2
    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. macrumors newbie

    #3
    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):
    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)
     
  4. macrumors 603

    #4
    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