I have a text file. There are 2 columns in each line, seperated by \t\t
as follows (c1 and c2 are strings might contain blankspace ):
c1\t\tc2
The lines are sorted by c2
How can I count the appearance of strings c2 and delete all the rows
that c2 appears just once in this file? How can I do that by just using
unix command or using awk or sed?
Thank a lot!
s***e 发帖数: 108
2
#!/usr/bin/awk -f
BEGIN { FS = "\t\t"; lastc2 = "" }
{ if ( lastc2 == $2 ) {
first = first + 1
if ( first == 1 ) {
print lastline "\n" $0
} else {
print $0
}
} else {
first = 0
}
lastline = $0
lastc2 = $2
}
【在 d**m 的大作中提到】 : I have a text file. There are 2 columns in each line, seperated by \t\t : as follows (c1 and c2 are strings might contain blankspace ): : c1\t\tc2 : The lines are sorted by c2 : How can I count the appearance of strings c2 and delete all the rows : that c2 appears just once in this file? How can I do that by just using : unix command or using awk or sed? : Thank a lot!