Apply if condition to all lines of tab delim which have same value in a particular column:


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Apply if condition to all lines of tab delim which have same value in a particular column:
# 1  
Old 09-21-2018
Apply if condition to all lines of tab delim which have same value in a particular column:

Apply if condition (in column 3rd ) to all lines of tab delim which have same value in a particular column (in this case column2)

Input:
Code:
id1 Disease1 High

id2 Disease1 Medium
id3 Disease1 Low
id4 Disease2 Low
id5 Disease3 Medium
id6 Disease3 Low

***
Expected output
Code:
id1 Disease1 High
id4 Disease2 Low
 id5 Disease3 Medium



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-21-2018 at 07:04 AM.. Reason: Added CODE tags.
# 2  
Old 09-21-2018
Welcome to the forum.


What "if condition (in column 3rd )" do you want applied? Not clear from your expected output. Please rephrase your request.
# 3  
Old 09-21-2018
Basically I want to apply if condition in lines which have same value in column2. In example first three lines have same value in column2 (Disease1 ) , now for these three line i want to aplly IF condition- if 3rd column is HIGH write only that line to output file , if 3rd column doesn't have HIGH, then look for MEDIUM and print it, if MEDIUM is also not there , then print line containing LOW value. Hope I have not confused it more
# 4  
Old 09-21-2018
Why don't you phrase your request more specifically, like you did in shell - Apply if condition to all lines of a tab delim file which have same value in a particular column: - Unix & Linux Stack Exchange

Last edited by RudiC; 09-21-2018 at 09:46 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. Shell Programming and Scripting

Read Two Columns - Apply Condition on Six other columns

Hello All, Here is my input univ1 chr1 100 200 - GeneA 500 1 0 0.1 0.2 0.3 0.4 0.5 univ1 chr1 100 200 - GeneA 600 1 0 0.0 0.0 0.0 0.0 0.1 univ1 chr1 100 200 - GeneA 700 1 0 0.4 0.4 ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

3. UNIX for Dummies Questions & Answers

Cut command, no input delim, output delim not working

Hello, I'm using cygwin on my Windows 7 machine. From the man pages of cut: --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter I tried the following commands and got the error messages: $ cut -c1-10,20-30 -d... (10 Replies)
Discussion started by: kojac
10 Replies

4. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

5. Shell Programming and Scripting

Comparing all lines in a column with another is condition is met

Sorry for this noob question, I have file with 4 columns like where columns 2 and 4 have numbers a 55 k 3 b 59 l 3 c 79 m 277 d 255 n 277 e 257 o 267 f 267 p 287 g 290 q 287 h 290 r 287 i 310 s 900 now i want to select only those rows, where values in column 4 are greater than... (4 Replies)
Discussion started by: amits22
4 Replies

6. UNIX for Dummies Questions & Answers

awk - Extract 4 lines in Column to Rows Tab Delimited between tags

I have tried the following to no avail. xargs -n8 < test.txt awk '{if(NR%6!=0){p=""}else{p="\n"};printf $0" "p}' Mod_Alm_log.txt > test.txt I have tried different variations of the above, the problem is mixes lines together. And it includes the tags "%a and %A" I need them to be all tab... (16 Replies)
Discussion started by: mytouchsr
16 Replies

7. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

8. Shell Programming and Scripting

to add special tag to a column based on column condition

Hi All, I have following html code <TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR> <TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR> <TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
Discussion started by: ckwan
9 Replies

9. Shell Programming and Scripting

Apply condition on fixed width file and filter records

Dear members.. I have a fixed width file. Requirement is as below:- 1. Scan each record from this fixed width file 2. Check for value under field no "6" equals to "ABC". If yes, then filter this record into the output file Please suggest a unix command to achieve this, my guess awk might... (6 Replies)
Discussion started by: sureshg_sampat
6 Replies

10. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies
Login or Register to Ask a Question