Sponsored Content
Full Discussion: awk if then else statement
Top Forums Shell Programming and Scripting awk if then else statement Post 302940270 by cmccabe on Thursday 2nd of April 2015 04:29:30 PM
Old 04-02-2015
awk if then else statement

I am using awk as part of and if then else statement. I am trying to have the user enter a gene name and then a variant or variants and have a specific transcript assigned to the variants depending on the gene. Below is my code but the if then else statement is wrong. Basically, the gene name would be the condition that assigns a particular transcript to a variant.

The desired output would be, if the user enters GJB2 as the gene name and then c.283G>A for the variant there is a statement for that condition that saves a file with NM_004004.5:c.283G>A . However if MECP2 is entered as the gene name and c.48delC,c.255G>T are entered as the variants, the a file is saved:

Code:
 
NM_004992.3:c.48delC
NM_004992.3:c.255G>T

Thank you Smilie.

Code:
 syntax() {
    printf "\n\n"
    printf "Please enter the gene name  : "; read gene
    printf "Enter variant(s): "; IFS="," read -a variants
        
        [ -z "$gene" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
        [ "$gene" = "end" ] && printf "\n Leaving match function." && sleep 2 && return

		awk '{ 
		if(${gene} = "GJB2")
        for ((i=0; i<${#variants[@]}; i++))
              do printf "NM_004004.5:%s\n" "${variants}" >> c:/Users/cmccabe/Desktop/Python27/$gene.txt >> c:/Users/cmccabe/Desktop/Python27/out.txt;
	    done
		else if(${gene} = "MECP2")
        for ((i=0; i<${#variants[@]}; i++))
		      do printf "NM_004992.3:%s\n" "${variants}" >> c:/Users/cmccabe/Desktop/Python27/$gene.txt >> c:/Users/cmccabe/Desktop/Python27/out.txt;
        done
		else if(${gene} = "Phox2B")
        for ((i=0; i<${#variants[@]}; i++))
		      do printf "NM_003924.3:%s\n" "${variants}" >> c:/Users/cmccabe/Desktop/Python27/$gene.txt >> c:/Users/cmccabe/Desktop/Python27/out.txt 
	    }'
	name
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

if statement in awk

Hi Friends How do I do two things from one if statement inside awk? I want to run a script and create a new file from the same condition. awk '{ if ($2 == ""){print " "|"cd /local/test; ./script.ksh"}{cat > ran_true.txt}}' $IN_FILE Bolded are the two things I want to be done. Thanks (1 Reply)
Discussion started by: UNovIX
1 Replies

2. Shell Programming and Scripting

awk inside another awk statement

hi all, i have two files 1) a.txt one two three 2) abc "one" = 10 pqr "three" = 20 345 "two" = 0 this is what i want in third file (3 Replies)
Discussion started by: shishirkotkar
3 Replies

3. Shell Programming and Scripting

awk, if statement

Having a little trouble with awk and an if statement. I have a test setup which I am trying to only print the records which start with the month 03. Everything I tried, prints everything, even the 02 month 03/23/2010 12:47:51 ga2828 SUBMITTED FROM URL: test123.cgi show port count ... (2 Replies)
Discussion started by: numele
2 Replies

4. Shell Programming and Scripting

Awk 'if' statement help

Hello all, I'm very new to this (<5hrs!) please bear with me. My file looks like this 386259.448541 417069.155 154935.157 186.206 162 1 1 8 386259.448551 417068.53 154935.04 186.144 156 1 1 8 386259.448561 417067.911 154934.926 186.175 164 1 1 8 386259.450337 417086.643 154946.483 894.671... (4 Replies)
Discussion started by: rebeccab37
4 Replies

5. Shell Programming and Scripting

Help Regarding AWk and IF THEN ELSE Statement

Hi, I have a data file which contains record count. So doing wc -l rightfit_balancing_count.dat | awk '{print $1}'] gives me the record count stored in the file. Now, i want to send a mail from UNIX, if the record count is equal to 0,otherwise it should do nothing. Any help... (2 Replies)
Discussion started by: Shell_Learner
2 Replies

6. Shell Programming and Scripting

awk if statement

hi, I have a l-column file of more than 10,000 lines with interspersed negative values. What I want to do is add a fixed number (360) everytime a negative value is encountered while leaving the positive ones as is. I need something that will read every line of the file and do the calculation... (3 Replies)
Discussion started by: ida1215
3 Replies

7. Shell Programming and Scripting

Help with awk statement

Hi I have a file with test test2 1000000657373 test1 test3 1000003849450 test2 test4 test5 100000837474 I cat the file and pipe it to an awk statement like so cat /tmp/file |awk '{if ($3 ~ "^*$" && $3 > 1024000000) print "/vol/"$1"/"$2;else if ($4 ~ "^*$" && $4 > 1024000000) print... (15 Replies)
Discussion started by: bombcan
15 Replies

8. Shell Programming and Scripting

If statement in awk

I run my script "switch.sh" repeatedly (within 30 seconds). Each time script is triggered, script itself should kill all previous process. Here is my code: for pid in $(ps -fe | grep 'switch.sh' | grep -v grep | awk '{if ($2<$$) print $2}'); do sudo kill -9 $pid done sleep 30 ... (6 Replies)
Discussion started by: armatron
6 Replies

9. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

10. Shell Programming and Scripting

awk statement help

There has to be a way to do this with awk or maybe I'm just focusing on the wrong tool and making this harder than it needs to be. I'm trying to do a file field lookup/join at a very large scale but the output changes has to change dramatically. I have an input file to do a field lookup from and... (3 Replies)
Discussion started by: brettcasper
3 Replies
Ace::Sequence::GappedAlignment(3pm)			User Contributed Perl Documentation		       Ace::Sequence::GappedAlignment(3pm)

NAME
Ace::Sequence::GappedAlignment - Gapped alignment object SYNOPSIS
# open database connection and get an Ace::Sequence object use Ace::Sequence; # get a megabase from the middle of chromosome I $seq = Ace::Sequence->new(-name => 'CHROMOSOME_I, -db => $db, -offset => 3_000_000, -length => 1_000_000); # get all the gapped alignments @alignments = $seq->alignments('EST_GENOME'); # get the aligned segments from the first one @segs = $alignments[0]->segments; # get the position of the first aligned segment on the # source sequence: ($s_start,$s_end) = ($segs[0]->start,$segs[0]->end); # get the target position for the first aligned segment ($t_start,$t_end) = ($segs[0]->target->start,$segs[0]->target->end); DESCRIPTION
Ace::Sequence::GappedAlignment is a subclass of Ace::Sequence::Feature. It inherits all the methods of Ace::Sequence::Feature, but adds the ability to retrieve the positions of the aligned segments. Each segment is an Ace::Sequence::Feature, from which you can retrieve the source and target coordinates. OBJECT CREATION
You will not ordinarily create an Ace::Sequence::GappedAlignment object directly. Instead, objects will be created in response to a alignments() call to an Ace::Sequence object. OBJECT METHODS
Most methods are inherited from Ace::Sequence::Feature. The following methods are also supported: segments() @segments = $gene->segments; Return a list of Ace::Sequence::Feature objects corresponding to similar segments. relative() $relative = $gene->relative; $gene->relative(1); This turns on and off relative coordinates. By default, the exons and intron features will be returned in the coordinate system used by the gene. If relative() is set to a true value, then coordinates will be expressed as relative to the start of the gene. The first exon will (usually) be 1. SEE ALSO
Ace, Ace::Object, Ace::Sequence,Ace::Sequence::Homol, Ace::Sequence::Feature, Ace::Sequence::FeatureList, GFF AUTHOR
Lincoln Stein <lstein@cshl.org> with extensive help from Jean Thierry-Mieg <mieg@kaa.crbm.cnrs-mop.fr> Copyright (c) 1999, Lincoln D. Stein This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 166: You forgot a '=back' before '=head1' perl v5.14.2 2001-11-10 Ace::Sequence::GappedAlignment(3pm)
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy