Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vanisha
    Member
    • Nov 2009
    • 21

    #1

    Help with awk

    Hi guys

    My knowledge on shell linux/unix is pretty basic. I need some help with a command I don't think is working, it may be something simple, which I find is usually the case with informatics!

    One line of my dataset looks like this:

    "exonic","GPR153","synonymous SNV","NM_207370:c.A144G.T48T",,,0.68,0.81,0.60,rs11590458,,1,6237409,6237409,T,C,"het","204","49","60"

    i want to pull out those lines which have values in columns 7, 8 and 9 (in this case the values in this line are 0.68,0.81,0.60,)

    Is there a simple way of doing this using awk?

    I initially tried matching those lines with no values in those columns with this command:

    awk '{ if ($7=="" && $8=="" && $9=="" && $10=="") print $0'} | wc -l

    but it doesn't work

    Any advice is appreciated!

    Cheers
  • essvee
    Member
    • Apr 2011
    • 11

    #2
    There is a fairly simple way, you were on the right track.

    try:

    awk '{print $7,$8,$9}' FS="," < (filename)

    and then you can redirect the stdout to a new file
    Hopefully this helps!

    Comment

    • pj_oz
      Junior Member
      • May 2009
      • 5

      #3
      You can also set the field separator within the awk code using 'BEGIN{FS=",";}' which can be helpful. Also, if you're checking for the presence of values, make sure to use !="" which checks that a value is not empty

      awk 'BEGIN{FS=",";}{ if ($7!="" && $8!="" && $9!=""){print $0}}' input_filename > output_filename

      Hope this helps!

      Comment

      • Vanisha
        Member
        • Nov 2009
        • 21

        #4
        That works, thanks guys!

        Comment

        • steven
          Senior Member
          • Aug 2009
          • 269

          #5
          I'd have done this:
          awk -F"," '$7 && $8 && $9' input > output

          If only the condition is specified, the default action is already "print $0". Also, "$N" as a condition should only return FALSE if the column is empty (but will be TRUE even for a 0 or a space).

          Comment

          • husamia
            Member
            • Apr 2010
            • 66

            #6
            try
            cut -f 7-9 inputfile > outputfile

            where 7-9 means cut columns 7 8 and 9
            if you want everything except those columns then use something like --complement

            Comment

            • steven
              Senior Member
              • Aug 2009
              • 269

              #7
              Originally posted by husamia View Post
              try
              cut -f 7-9 inputfile > outputfile

              where 7-9 means cut columns 7 8 and 9
              if you want everything except those columns then use something like --complement
              I think vanisha wanted lines in output, not just columns ("i want to pull out those lines which have values in columns 7, 8 and 9").

              Comment

              • rahulvarma
                Junior Member
                • Aug 2011
                • 9

                #8
                hi guys!
                i am dealing with the problem where in single file 3 different columns are there.

                eg:
                1 7 -0.2567
                2 8 -0.4321
                2 10 -0.4560
                3 12 -0.2210
                4 12 -0.3243
                5 11 -0.9870
                5 15 -0.7860
                6 16 -0.2345

                description:whn (1) link with (7) its energy is [-0.2567]
                same things follws

                if u look at col 1
                (2) is linked with (8) &(10) of column two and gives respective energy( -0.4321)& (-0.4560) .in those cases i would prefer the least energy say (-0.4321)

                same case whn we look into coumn 2 value (12) two option exist like 3 (-0.2210) &
                4( -0.3243).i would prefer least one as mention early (-0.2210)


                so finally the result should something like below:

                1 7 -0.2567
                2 8 -0.4321
                3 12 -0.2210
                5 15 -0.7860
                6 16 -0.2345

                can any one hlep me to get this...
                thanks in advance....

                Comment

                • pj_oz
                  Junior Member
                  • May 2009
                  • 5

                  #9
                  Hi rahulvarma,

                  Looking at your question, while it could be achieved by scripting in awk it is a more complex question than just pulling lines with a value in certain columns. You would need to script it according to the parameters you've set. Something like the following nearly works in awk, it currently gives the wrong results but it might give you a start in resolving your problem.

                  Code:
                  #!/usr/bin/awk
                  BEGIN{
                          lastnumber1=0;
                          lastnumber2=0
                          energy=0;
                          toprint=0;
                          alreadydone=0;
                  }
                  
                  {
                          if (lastnumber1==$1) {
                                  if ($3>energy and lastnumber1 != 0) {
                                          toprint = $0;
                                  }
                          } else if (lastnumber2 == $2) {
                                  if ($3>energy and lastnumber2 != 0) {
                                          toprint = $0;
                                  }
                          } else {
                                  if (toprint != 0) {
                                          print toprint;
                                  } else {
                                          print lastline;
                                  }
                                  toprint = 0;
                          }
                  
                          lastnumber1 = $1;
                          lastnumber2 = $2;
                          energy = $3;
                          lastline = $0;
                  }
                  On your test set it gives the results:
                  1 7 -0.2567
                  2 10 -0.4560
                  4 12 -0.3243
                  5 15 -0.7860

                  Good luck!

                  Comment

                  • rahulvarma
                    Junior Member
                    • Aug 2011
                    • 9

                    #10
                    hi pj_oz,
                    thank you soo much for your effort.
                    appreciate your work.

                    Comment

                    Latest Articles

                    Collapse

                    • SEQadmin2
                      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                      by SEQadmin2



                      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                      ...
                      10-14-2026, 09:55 AM
                    • SEQadmin2
                      New Genomics Technologies Take Aim at Long-Standing Limits
                      by SEQadmin2


                      Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                      We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                      ...
                      09-28-2026, 10:25 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, 10-15-2026, 10:52 AM
                    0 responses
                    26 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-14-2026, 05:39 AM
                    0 responses
                    32 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-13-2026, 09:56 AM
                    0 responses
                    28 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 10-09-2026, 11:14 AM
                    0 responses
                    28 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...