Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I am using awk to manipulate files. For each file (each chromosome) , I have been using the following commands to get the files in the right configuration: gawk ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    5

    Using awk/gawk to switch columns and replacing entires within a column


    Hi,

    I am using awk to manipulate files.

    For each file (each chromosome) , I have been using the following commands to get the files in the right configuration:

    gawk 'sub($1,1)' chr1a.map>chr1.map
    which replaces the 0's in the first column to the chromosome # (here 1 for chr1 file).

    gawk '{temp=$1;$1=$2;$2=temp}{print}' chr1a.ped>chr1.ped
    which switches column 1 with column 2.

    Is there anyway I can do it all for all 44 (22 map and 22 ped) files?

    For the map files, I have tried the following which didn't work.

    for ((i=1;i<=22;++i)); do cmd="gawk 'sub($1,"$i")' chr"i".map"; eval $cmd; done

    Thanks for your help,

    Joey

  2. #2
    Just Joined!
    Join Date
    Aug 2006
    Posts
    16

    skip the eval...

    I think I would simplify life and do it this way:

    for ((i=1;i<=22;++i));
    do
    gawk 'sub($1,"$i")' < chr"$i".map | awk '{print $2, $1}' > tmp$$
    mv tmp$$ chr"$i".map
    done

    Quote Originally Posted by joy_stat View Post
    Hi,

    I am using awk to manipulate files.

    For each file (each chromosome) , I have been using the following commands to get the files in the right configuration:

    gawk 'sub($1,1)' chr1a.map>chr1.map
    which replaces the 0's in the first column to the chromosome # (here 1 for chr1 file).

    gawk '{temp=$1;$1=$2;$2=temp}{print}' chr1a.ped>chr1.ped
    which switches column 1 with column 2.

    Is there anyway I can do it all for all 44 (22 map and 22 ped) files?

    For the map files, I have tried the following which didn't work.

    for ((i=1;i<=22;++i)); do cmd="gawk 'sub($1,"$i")' chr"i".map"; eval $cmd; done

    Thanks for your help,

    Joey

Posting Permissions

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