Sponsored Content
Full Discussion: Multi-conditional IF - awk
Top Forums Shell Programming and Scripting Multi-conditional IF - awk Post 303014831 by Geneanalyst on Wednesday 21st of March 2018 03:36:12 PM
Old 03-21-2018
Question Multi-conditional IF - awk

I have a 6 column array with 2 million rows that looks like this:
Code:
1 1089699 rs6686003 G A g     
1 1090557 rs7553429 A C c     
1 1094738 rs4970362 A G a     
1 1099342 rs9660710 A C c     
1 1106473 rs4970420 G A a     
1 1108637 rs4970421 G A g     
1 1119858 rs1320565 C T c     
1 1120431 rs1320571 G A A

I need to change all lower case letters in the 6th column to uppercase. I wrote the following script, but all it is doing is changing every value in the 6th column to "A"

Code:
awk '{ 
if ($6="a") $6="A"; 
else if ($6="c") $6="C"; 
else if ($6="g") $6="G"; 
else if ($6="t") $6="T"; 
print $0;
}'

This is what I'm getting:

Code:
1 1089699 rs6686003 G A A
1 1090557 rs7553429 A C A
1 1094738 rs4970362 A G A
1 1099342 rs9660710 A C A
1 1106473 rs4970420 G A A
1 1108637 rs4970421 G A A
1 1119858 rs1320565 C T A
1 1120431 rs1320571 G A A

I have Ubuntu 16.04 LTS. Any help would be greatly appreciated.

Last edited by Geneanalyst; 03-21-2018 at 04:38 PM.. Reason: added info
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk conditional statement

how can i use awk or sed to do a conditional statement, so that HH:MM if MM not great than 30 , then MM=00 else MM=30 ie: 10:34 will display 10:30 10:29 will display 10:00 a=$(echo 10:34 | awk ......) Thanks in advance (10 Replies)
Discussion started by: 3Gmobile
10 Replies

2. Shell Programming and Scripting

AWK - conditional cause

Hello guys, I want to make a conditional cause in the following file using awk: awk '{ if ($2 != 0) print $1, $2, $3}' test.csv > test2.csv FILE EXAMPLE = test.csv string,number,date abc,0,20050101 def,1,20060101 ghi,2,20040101 jkl,12,20090101 mno,123,20020101 ... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies

3. Shell Programming and Scripting

Awk Conditional

Hi Guys, i have this files: xyz20080716.log opqrs20080716.log abcdef20080716.log xyz20080717.log oprs20080717.log abcde20080717.log currentdate: 20080717.log I want to make script to zip the file for past day. Can anyone help for this? i've just learn awk scripting & still confused with... (3 Replies)
Discussion started by: icy_blu_blu
3 Replies

4. Shell Programming and Scripting

awk conditional assignment

Dear all, I want to use awk to read the three columns in a file called "test" and change them to ( 1.5 1.5 1.5) if any element is found to be greater than three. A part of the file is shown below: (0.478318 0.391032 -0.14054) (0.45562 0.392523 -0.121685) (0.437204 0.392811 -0.106158)... (3 Replies)
Discussion started by: mfmohdyasin
3 Replies

5. Shell Programming and Scripting

Conditional Multi-Line Grep Problem

Hi, I have a very large file I want to extract lines from. I'm hoping Grep can do the job, but I'm running into problems. I want to return all lines that match a pattern. However, if the following line of a matched line contains the word "Raw" I want to return that line as well. Is this... (3 Replies)
Discussion started by: redbluefish
3 Replies

6. Shell Programming and Scripting

AWK conditional addition

I have a column of numbers $2, I would like to add 360 to all numbers that are negative. This method seems a bit convoluted, and does not work (outputs 0): BEGIN { A=sprintf("%d", $2); if(A<0) A=A+360; BIN++; } END { for(A in BIN) print... (5 Replies)
Discussion started by: chrisjorg
5 Replies

7. Shell Programming and Scripting

conditional statement in awk

Hi all, I have a file containing the values that would be use as the basis for printing the lines of another set of files using awk. What I want to do is something like the one below: stdev.txt 0.21 0.42 0.32 0.25 0.15 file1.txt file2.txt file3.txt ..filen.txt 0.45 0.23 ... (4 Replies)
Discussion started by: ida1215
4 Replies

8. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

9. Shell Programming and Scripting

Conditional awk

Hello All, I have a file like this: bash-3.00$ cat 1.txt 201112091147|0|1359331220|1025 201112091147|0|1359331088|1024 201112091144|0|1359331172|1025 201112091147|0|1359331220|1021 201112091149|0|1359331088|1027 201112091144|0|1359331172|1029 and a list of MSISDNs in another file... (9 Replies)
Discussion started by: EAGL€
9 Replies

10. Shell Programming and Scripting

awk conditional output

Hello, How can I use a conditional to produce an output file that varies with respect to the contents of column #4 in the data file: Data file: 9780020080954 9.95 0.49 AS 23.3729 9780020130857 9.95 0.49 AS 23.3729 9780023001406 22.20 0.25 AOD ... (12 Replies)
Discussion started by: palex
12 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 11:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy