Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print duplicates in column to another file

Status
Not open for further replies.

spconway

MIS
May 25, 2000
16
0
0
US
I don't know if awk is right for this? Would like your opinion and a little kickstart with an awk script please.
I am still new to awk and am trying to pull out all duplicates from fifth (8 digit columm) column of the following log file:

114 0 REC 19 14845445 X L
121 0 REC 19 14845445 X L
114 0 REC 19 14845449 X L
114 0 REC 19 15131591 X L
131 0 REC 19 15131591 X L
114 0 REC 19 15131712 X L
114 0 REC 19 15131734 X L
114 0 REC 19 15131740 X L
114 0 REC 19 15131850 X L
114 0 REC 19 15131941 X L
114 0 REC 19 15131971 X L
114 0 REC 19 15132005 X L

I need to pipe all dupe occurances with full line to another file.
The first column shows user session the fifth column is a record id. I am trying to see how many dupes are occuring in recid column and be able to print out the recid and the user id's to another file. Eventually this is going to be run from a korn script so operator can see the dupe recids.

Thanks
spconway@comcast.net
 
Try this
Code:
#!/bin/awk -f

BEGIN {
  lastrec = ""
  lastline = ""
}

# same record as previous
lastrec == $5 {
  # print last line (once)
  if ( lastline != "" ) print lastline
  lastline = ""

  # print current line
  print $0
  next
}

# record each line
{
  lastrec = $5
  lastline = $0
}

--
 
you can adjust the print statement to your likings:

nawk -f spc.awk spc.txt

#---------------------- spc.awk
BEGIN {

FLD_user="1"
FLD_rec="5"
}

{
arrR[$FLD_rec]++;
arr[$FLD_user , $FLD_rec];
}

END {
for (i in arr) {
split(i, tmp, SUBSEP);
if (arrR[tmp[2]] > 1 )
printf("%s %s count->[%d]\n", tmp[1], tmp[2], arrR[tmp[2]])
}
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top