How to ignore relative few occurrences of a field value?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ignore relative few occurrences of a field value?
# 1  
Old 12-17-2013
How to ignore relative few occurrences of a field value?

Hi experts,

I have a very long file that looks about like this.

Code:
aaad_1577 64000
aaad_1577 72000
aaad_1577 72000
aaad_1577 65000
aaad_1577 65000
(...aaad about a thousand times...)
bbbd_2002 56000
bbbd_2002 57000
bbbd_3045 57000
cccd_3452 150000
dddd_6014 150000
dddd_6014 150000
dddd_6014 150000
(...dddd about a thousand times...)

I want to ignore the rows where the first column values occur fewer than handful of times, say 5 times.

It would be helpful if I could see how many occurrences I'm getting before I ignore them so I can go from this:

Code:
aaad_1577 64000 1005
aaad_1577 72000 1005
aaad_1577 72000 1005
aaad_1577 65000 1005
aaad_1577 65000 1005
(...aaad about a thousand times...)
bbbd_2002 56000 2
bbbd_2002 57000 2
bbbd_3045 57000 1
cccd_3452 150000 1
dddd_6014 150000 1003
dddd_6014 175000 1003
dddd_6014 150000 1003
(...dddd about a thousand times...)

to using this:

awk '{ if ($3>3) print $0}' [file]

and get this:

Code:
aaad_1577 64000 1005
aaad_1577 72000 1005
aaad_1577 72000 1005
aaad_1577 65000 1005
aaad_1577 65000 1005
(...aaad about a thousand times...)
dddd_6014 150000 1003
dddd_6014 175000 1003
dddd_6014 150000 1003
(...dddd about a thousand times...)


Thank you!
# 2  
Old 12-17-2013
Try

Code:
$ cat file
aaad_1577 64000
aaad_1577 72000
aaad_1577 72000
aaad_1577 65000
aaad_1577 65000
bbbd_2002 56000
bbbd_2002 57000
bbbd_3045 57000
cccd_3452 150000
dddd_6014 150000
dddd_6014 150000
dddd_6014 150000

Code:
$ awk 'FNR==NR{A[$1]++;next}{print $0,A[$1]}' file file

Code:
aaad_1577 64000 5
aaad_1577 72000 5
aaad_1577 72000 5
aaad_1577 65000 5
aaad_1577 65000 5
bbbd_2002 56000 2
bbbd_2002 57000 2
bbbd_3045 57000 1
cccd_3452 150000 1
dddd_6014 150000 3
dddd_6014 150000 3
dddd_6014 150000 3

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 12-17-2013
That'll do it!
Thanks Akshay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to ignore whitespace in field

The awk below executes and update the desired field in my first awk. However, the white space between nonsynonymous SNV in $9 is being split into tabs and my attempt to correct this does not update the field unless it is removed. I am not sure what I am doing wrong? Thank you :). file1 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

How can awk ignore the field delimiter like comma inside a field?

We have a csv file as mentioned below and the requirement is to change the date format in file as mentioned below. Current file (file.csv) ---------------------- empname,date_of_join,dept,date_of_resignation ram,08/09/2015,sales,21/06/2016 "akash,sahu",08/10/2015,IT,21/07/2016 ... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

3. UNIX for Dummies Questions & Answers

Relative Pathnames

Hi, Could anyone help me with the following questions about relative addressing. The questions are: 1) Enter below the command to copy the file basics.pptto the folder outline, using relative addressing. 2) Enter below to move the file .secrets.doc to the folder Day1 using relative addressing.... (1 Reply)
Discussion started by: ml123
1 Replies

4. UNIX for Dummies Questions & Answers

Help with cp command using relative path?

I have a lab I am doing for a Linux Operating class. The question I am stumped on is "For the following questions, only use the cp command to copy files. You should currently be inside your lab07 directory. Create a subdirectory inside this directory called ones and copy (working ... (1 Reply)
Discussion started by: CodyMongrel
1 Replies

5. UNIX for Dummies Questions & Answers

Relative column offsets

Ive been trying to slide the second column one line down while keeping the first one in place. For a start, I tried to see if I can go through every line and print the element located on the line below with the following command, but it didnt work. Maybe awk is not the right way to do it. Matlab... (6 Replies)
Discussion started by: Alabama
6 Replies

6. Shell Programming and Scripting

Relative path not safe

Hallo everyone, I am running an SQL-Script over KShell-Script. Thus, in the KShell-Script there are these lines: WORKPATH=$PWD/work EXPORTDIR=export_meine_datei_bitte EXPORTPATH=${WORKPATH}/${EXPORTDIR} ... db2 connect to ${DBNAME} || die "can not open database connection" db2... (9 Replies)
Discussion started by: ratnalein88
9 Replies

7. UNIX for Dummies Questions & Answers

problem with relative pathing

Hi all, My directory structure is as follows home /md/DEV/SCRIPTS/DAILY and home/md/DEV/MIS/LANDING so this command find home/md/DEV/MIS/LANDING -name MIS_Customer_\* is giving me the desired output ... (1 Reply)
Discussion started by: rajarp
1 Replies

8. UNIX for Dummies Questions & Answers

get cygpath to leave relative paths as relative?

If I execute mypath=`cygpath -w ../` echo $mypath I get d:\unix\nextVersion\script OK, d:\unix\nextVersion\script is the correct windows version of the path, but it is in absolute form. I would prefer it if cygpath left it in relative form, i.e. echo $mypath should output ..\ ... (0 Replies)
Discussion started by: fabulous2
0 Replies

9. UNIX for Dummies Questions & Answers

list all ports and their relative IP@ if any

Hi all i'm working on a LINUX-based platform. i'm little confused with PORTs. i have my platform connected to many other platforms, i need to know the relative port for each IP@. i know the IP of each connected platform to mine, but i'm not sure about the relative PORT for each platform...... (4 Replies)
Discussion started by: samsal_991
4 Replies

10. Programming

relative pointers on Unix

Hi all: We're porting lot of C code from Windows to Unix. In Windows we're using relative pointers (with the _based keyword) to access some structures placed on shared memory. We would need something like the Microsoft's _based keyword for unix. Does something similar exist in Unix? If not, is... (3 Replies)
Discussion started by: rahul_verma
3 Replies
Login or Register to Ask a Question