I am new beginner, and just got help from this forum. The command line is :
awk '($1, $2) in x {
print x[$1, $2]
print
delete x[$1, $2]
next
}
{ x[$2, $1] = $0
}' results>myfile
I got a output "myfile" from the orginal file 'results'. The quesion is I don't know how to get all rows that are not shown in output file, or i just want to do negative selection. I think there is a way to do that ,but I spent hours and still have no idea. My previous question was here:
Try this slight modification to your previous script. It produces two output files. The matched pairs of input lines will be written to the file named matched and the remaining input lines will be written to the file named unmatched :
awk '
($1, $2) in x {
print x[$1, $2] > "matched"
print > "matched"
delete x[$1, $2]
next
}
{ x[$2, $1] = $0
}
END { for(key in x)
print x[key] > "unmatched"
}' results
As with the code before, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .
Thank you for the information. The question is that the number of matched and unmatched lines are not equal to the total lines. I don't know where is wrong. I think the problem is that many A-B, B-A, pattern recurring many times but other values is different (in 3rd, 4th column etc). so the unmatched lines is significant lower than the rest of matched.
I upload a very small sample size. 19 in total. The command gives the 11, 6 , respectively. I don't know what's wrong. Maybe something wrong with my format?
oh, I realized that I didn't remove A-B, A-B pattern, the lines has the same value for first two columns.
Please paste the 19 lines in CODE tags into a post so we can see what you are starting with. If you can craft the output you would expect in a separate part (also wrapped in CODE tags) then that will help us to help you.