Sponsored Content
Top Forums Shell Programming and Scripting Awk to find duplicates in 2nd field Post 302315574 by vgersh99 on Tuesday 12th of May 2009 07:24:54 PM
Old 05-12-2009
Quote:
Originally Posted by zenith
I want to find duplicates in file on 2nd field i wrote this code:
Code:
nawk '{a[$2]++} END{for i in a {if (a[i]>1) print}}' temp

Could not find whats wrong with this.
Appreciate help
Hint: what are trying to 'print'?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: find and replace in certain field only, help needed

I got a sample file like this. $ cat test 12|13|100|s 12|13|100|s 100|13|100|s 12|13|100|s I want to replace all 100 by 2000 only in 3rd field using "awk" This is replacing all 100's :-( $ awk -F "|" '{gsub( /100/,"2000");print}' test 12|13|2000|s 12|13|2000|s 2000|13|2000|s... (5 Replies)
Discussion started by: jkl_jkl
5 Replies

2. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

3. Shell Programming and Scripting

how to find the 2nd field

java....4059... compsite 62u IPv4 170747 TCP *:9400 (LISTEN) java...... 05... compsite 109u IPv4 171216 TCP *:9401 (LISTEN) This is Joust formated like this Please Repace "." with space" " All are Right Justfied Output :- 4058 and 05 so that i can kill this (1 Reply)
Discussion started by: pareshpatra
1 Replies

4. Shell Programming and Scripting

awk to compare 2nd and 3rd field and print the differences

need a one liner to compare 2nd and 3rd field and print values that are not matched in 2nd field Input col 2 col 3 1.1.1.1 11.11.11.11 8.8.8.8 0.0.0.0 3.3.3.3 2.2.2.2 7.7.7.7 3.3.3.3 5.5.5.5 1.1.1.1 4.4.4.4 6.6.6.6 9.9.9.9 output 7.7.7.7 ... (12 Replies)
Discussion started by: chidori
12 Replies

5. Shell Programming and Scripting

Remove duplicates based on a field's value

Hi All, I have a text file with three columns. I would like a simple script that removes lines in which column 1 has duplicate entries, but use the largest value in column 3 to decide which one to keep. For example: Input file: 12345a rerere.rerere len=23 11111c fsdfdf.dfsdfdsf len=33 ... (3 Replies)
Discussion started by: anniecarv
3 Replies

6. Shell Programming and Scripting

Find duplicates in column 1 and merge their lines (awk?)

Hi, I have a file (sorted by sort) with 8 tab delimited columns. The first column contains duplicated fields and I need to merge all these identical lines. My input file: comp100002 aaa bbb ccc ddd eee fff ggg comp100003 aba aba aba aba aba aba aba comp100003 fff fff fff fff fff fff fff... (5 Replies)
Discussion started by: falcox
5 Replies

7. Shell Programming and Scripting

Deleting only 2nd and third duplicates in field 2

(7 Replies)
Discussion started by: newbie2010
7 Replies

8. Shell Programming and Scripting

Find and delete part of field with awk or sed

I've got a file that looks like this (the whitespace between commas is intentional): 123456789,12,JOHN H DOE ,DOE/JOHN H ,,,DOE/JOHN H ,,,,,123 FAKE STREET ,SPRINGFIELD,XX, I want to strip just the first name out of the third field so it reads "JOHN,". So far I... (6 Replies)
Discussion started by: Scottie1954
6 Replies

9. Shell Programming and Scripting

Find and copy files with field lower than a value, awk?

Hi all! I have 10.000 files having generally this format: text text text text num text num text num text text text GAP number text text text num text num text num RMS num text num text num text num ... what I want is to copy the files if the GAP number is lower than a value e.g. <100... (5 Replies)
Discussion started by: phaethon
5 Replies

10. UNIX for Dummies Questions & Answers

Combine Similar Output from the 2nd field w.r.t 1st Field

Hi, For example: I have: HostA,XYZ HostB,XYZ HostC,ABC I would like the output to be: HostA,HostB: XYZ HostC:ABC How can I achieve this? So far what I though of is: (1 Reply)
Discussion started by: alvinoo
1 Replies
form_field_new(3CURSES) 				     Curses Library Functions					   form_field_new(3CURSES)

NAME
form_field_new, new_field, dup_field, link_field, free_field - create and destroy forms fields SYNOPSIS
cc [ flag... ] file... -lform -lcurses [ library... ] #include <form.h> FIELD *new_field(int r, int c, int frow, int fcol, int nrow, int ncol); FIELD *dup_field(FIELD *field, int frow, int fcol); FIELD *link_field(FIELD *field, int frow, int fcol); int free_field(FIELD *field); DESCRIPTION
new_field() creates a new field with r rows and c columns, starting at frow, fcol, in the subwindow of a form. nrow is the number of off- screen rows and nbuf is the number of additional working buffers. This routine returns a pointer to the new field. dup_field() duplicates field at the specified location. All field attributes are duplicated, including the current contents of the field buffers. link_field() also duplicates field at the specified location. However, unlike dup_field(), the new field shares the field buffers with the original field. After creation, the attributes of the new field can be changed without affecting the original field. free_field() frees the storage allocated for field. RETURN VALUES
Routines that return pointers return NULL on error. free_field() returns one of the following: E_OK Thefunction returned successfully. E_CONNECTED The field is already connected to a form. E_SYSTEM_ERROR System error. E_BAD_ARGUMENT An argument is incorrect. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curses(3CURSES), forms(3CURSES), attributes(5) NOTES
The header <form.h> automatically includes the headers <eti.h> and <curses.h>. SunOS 5.11 31 Dec 1996 form_field_new(3CURSES)
All times are GMT -4. The time now is 08:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy