Sponsored Content
Top Forums Shell Programming and Scripting Print unique records in 2 columns using awk Post 302726291 by ctsgnb on Sunday 4th of November 2012 04:18:34 AM
Old 11-04-2012
Please note that Scrutinizer's code assume that for a certain $1, the first value in the second column is 1, according to the example you gave.

If it happen that you have an input file like :
Code:
awex1   1
awex1   2
awex1   3
assww   5
ader34   1
ader34   2

And if you expect the output:
Code:
assww   5

You could then go for the line i proposed in post #2
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AWK ??-print for fields within records in a file

Hello all, Would appreciate if someone can help me out on the following requirement. INPUT FILE: -------------------------- TPS REPORT abc def ghi jkl mon pqr stu vrs lll END OF TPS REPORT TPS REPORT field1 field2 field3 field4 field5 field6 (8 Replies)
Discussion started by: hyennah
8 Replies

2. Shell Programming and Scripting

awk : extracting unique lines based on columns

Hi, snp.txt CHR_A SNP_A BP_A_st BP_A_End CHR_B BP_B SNP_B R2 p-SNP_A p-SNP_B 5 rs1988728 74904317 74904318 5 74960646 rs1427924 0.377333 0.000740085 0.013930081 5 ... (12 Replies)
Discussion started by: genehunter
12 Replies

3. Shell Programming and Scripting

awk print only select records from file2

Print only records from file 2 that do not match file 1 based on criteria of comparing column 1 and column 6 Was trying to play around with following code I found on other threads but not too successful Code: awk 'NR==FNR{p=$1;$1=x;A=$0;next}{$2=$2(A?A:",,,")}1' FS=~ OFS=~ file1 FS="*"... (11 Replies)
Discussion started by: sigh2010
11 Replies

4. Shell Programming and Scripting

count the unique records based on certain columns

Hi everyone, I have a file result.txt with records as following and another file mirna.txt with a list of miRNAs e.g. miR22, miR123, miR13 etc. Gene Transcript miRNA Gar Nm_111233 miR22 Gar Nm_123440 miR22 Gar Nm_129939 miR22 Hel Nm_233900 miR13 Hel ... (6 Replies)
Discussion started by: miclow
6 Replies

5. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

6. Shell Programming and Scripting

Print unique names in a specific column using awk

Is it possible to modify file like this. 1. Remove all the duplicate names in a define column i.e 4th col 2. Count the no.of unique names separated by ";" and print as a 5th col thanx in advance!! Q input c1 30 3 Eh2 c10 96 3 Frp c41 396 3 Ua5;Lop;Kol;Kol c62 2 30 Fmp;Fmp;Fmp ... (5 Replies)
Discussion started by: quincyjones
5 Replies

7. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

8. Shell Programming and Scripting

awk to print unique text in field

I am trying to use awk to print the unique entries in $2 So in the example below there are 3 lines but 2 of the lines match in $2 so only one is used in the output. File.txt chr17:29667512-29667673 NF1:exon.1;NF1:exon.2;NF1:exon.38;NF1:exon.4;NF1:exon.46;NF1:exon.47 703.807... (5 Replies)
Discussion started by: cmccabe
5 Replies

9. Shell Programming and Scripting

awk to print unique text in field before hyphen

Trying to print the unique values in $2 before the -, currently the count is displayed. Hopefully, the below is close. Thank you :). file chr2:46603668-46603902 EPAS1-902|gc=54.3 253.1 chr2:211471445-211471675 CPS1-1205|gc=48.3 264.7 chr19:15291762-15291983 NOTCH3-1003|gc=68.8 195.8... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. Shell Programming and Scripting

Issue using awk to print min values for unique ids

I am using the following script to search for and print minimum values for each individual Fields (3-14) for each unique id (Field 1). But when the field contains a "-99.99" ( I am ignoring "-99.99") and when the minimum value is the first line of a new id (Field 1), the output does not print Field... (13 Replies)
Discussion started by: ncwxpanther
13 Replies
COLORS(3)						   libbash colors Library Manual						 COLORS(3)

NAME
colors -- libbash library for setting tty colors. SYNOPSIS
colorSet <color> colorReset colorPrint [<indent>] <color> <text> colorPrintN [<indent>] <color> <text> DESCRIPTION
General colors is a collection of functions that make it very easy to put colored text on tty. The function list: colorSet Sets the color of the prints to the tty to COLOR colorReset Resets current tty color back to normal colorPrint Prints TEXT in the color COLOR indented by INDENT (without adding a newline) colorPrintN The same as colorPrint, but trailing newline is added Detailed interface description follows. Available colors: Green Red Yellow White The color parameter is non-case-sensitive (i.e. RED, red, ReD, and all the other forms are valid and are the same as Red). FUNCTIONS DESCRIPTIONS
colorSet <color> Sets the current printing color to color. colorReset Resets current tty color back to normal. colorPrint [<indent>] <color> Prints text using the color color indented by indent (without adding a newline). Parameters: <indent> The column to move to before start printing. This parameter is optional. If ommitted - start output from current cursor position. <color> The color to use. <color> The text to print. colorPrintN [<indent>] <color> The same as colorPrint, except a trailing newline is added. EXAMPLES
Printing a green 'Hello World' with a newline: Using colorSet: $ colorSet green $ echo 'Hello World' $ colorReset Using colorPrint: $ colorPrint 'Hello World'; echo Using colorPrintN: $ colorPrintN 'Hello World' AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 05:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy