Reputation: 489
I have a list of text that looks like this:
function.o U out
function.o T fail
function.o U main
myPart.o T out
myPart.o U fail
and so on...
I want the final list to look like this:
The .o file with U beside it : The .o file with T beside it /the third column they have both/
So the example up there would look like this filtered:
function.o : myPart.o /out/
myPart.o : function.o /fail/
So I list only the lines that have the same symbol in the third column (like out, fail and so on). Until now I came up with this:
awk '$3 in t{ln[$3]=t[$3]" -> "$1;next}{t[$3]=$1}END{for(s in ln) print ln[s],"("s")"}' "$file"
But that prints everything without accounting for the U/T symbol. Any ideas please?
Upvotes: 1
Views: 48
Reputation: 77105
$ awk '
$3 in t{line[$3]=($2=="U")?$1" : "t[$3]:t[$3]" : "$1;next}{t[$3]=$1}
END{for(k in line) print line[k],"/"k"/"}
' file
myPart.o : function.o /fail/
function.o : myPart.o /out/
Upvotes: 1
Reputation: 80931
Does this do what you want?
{
file[$3,$2] = $1
thirds[$3]++
}
END {
for (third in thirds) {
if (file[third,"T"]) {
print file[third,"T"], ":", file[third,"U"], "/" third "/"
}
}
}
Upvotes: 0