Filter duplicates in file by using columns as parameters (grep linux) -
i looking pattern #type in set of files. output should return lines containing pattern. lines organized columns tab separator:
<subject1> <#type> <object1> <subject2> <#type> <object1> <subject3> <#type> <object2> <subject4> <#type> <object2> <subject5> <#type> <object3> for purpose using command ack-grep:
$ack-grep "#type" i can use sed as:
sed -n -e "/#type/p;q" *.nt
the problem duplicates should avoid objects. output should having:
<subject1> <#type> <object1> <subject3> <#type> <object2> <subject5> <#type> <object3>
why don't use old grep? should basically:
grep '#type' *.nt to avoid duplicates in objectn part can use uniq --skip-fields option:
grep '#type' *.nt | sort -k3,3 | uniq --skip-fields 2 however, output needs sorted before using uniq.
Comments
Post a Comment