Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2009
    Posts
    3

    Unanswered: awk print tab delimited new line file; Need help urgently

    I am trying to print out my file in tab delimited formatted along with a new line after end of each line. However I am missing out on the combination I need to put for printing out this format.
    Following is my input file: ( this is a space delimited file)
    NA18558 NA18609 NA18537 NA18632 NA18564 NA18582 NA18561 NA18611 NA18540 NA18633 NA18566 NA18592 NA18562 NA18612 NA18542NA18635 NA18570 NA18593 NA18563 NA18620 NA18545 NA18636 NA18571 NA18594 NA18572 NA18621 NA18547 NA18637 NA18573 NA18603NA18526 NA18622 NA18550 NA18576 NA18524 NA18605 NA18529 NA18623 NA18552 NA18577 NA18608 NA18532 NA18624 NA18555 NA18579
    rs4880608 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 NA 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2

    I am planning to print it out as tab delimited file.

    Here is my shell script.

    #!/bin/sh
    awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } }' CHB_NS_SNP.NEW.txt

    I am print columns 1 -45 ie. the entire width of the file and want to add a \n in the shell scipt. Only I am not sure how to do it.

    Thanks for your help.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Try:
    Code:
    awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } print; }' CHB_NS_SNP.NEW.txt
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Aug 2009
    Posts
    3

    thanks

    Quote Originally Posted by LKBrwn_DBA View Post
    Try:
    Code:
    awk '{ for (x=1; x<=46; x++) { printf "%s\t", $x } print; }' CHB_NS_SNP.NEW.txt
    Thanks LKBrwn. IT works!

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink

    yw........
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Alternatively:
    Code:
    sed "s/ /<tab>/g" input.file >output.file
    #where <tab> is replaced with the actual tab character

  6. #6
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Alternatively:
    Code:
    tr ' ' '\t' <input.file >output.file

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •