是否有一种方法可以根据字段为仅出现一次的行过滤文件?

问题描述 投票:-1回答:1

我有一个“ diff like”文件,其中各字段之间用制表符分隔。有没有办法只使用标准的gnu工具来获得仅出现一次的行,如果第二行相等,则这两行相等。

基本上,我只想为新行和已删除行而不是已编辑行过滤此文件。

[文件首先按第二列(名称)排序,然后按第一列(减法然后是加法)排序。

<   Chandler Hutchison  Chicago Bulls   Wed, Oct 30, 2019   Out (Hamstring) - The Bulls have listed Hutchison as OUT for Wednesday's (Oct. 30) game against the Cavs.
>   Chandler Hutchison  Chicago Bulls   Thu, Oct 31, 2019   Out (Hamstring) - The Bulls have listed Hutchison as OUT for Friday's (Nov. 1) game.
>   Daniel Theis    Boston Celtics  Thu, Oct 31, 2019   Day To Day (Left Ankle) - Boston Celtics F-C Daniel Theis is probable for Friday's (Nov. 1) game against New York right a left ankle sprain.
<   Edmond Sumner   Indiana Pacers  Wed, Oct 30, 2019   Day To Day (Hand) - Sumner is OUT for Wednesday's game (Oct. 30) against the Nets.
>   Edmond Sumner   Indiana Pacers  Thu, Oct 31, 2019   Out (Hand) - Sumner will miss at least three weeks with a non-displaced fracture in his right hand.
<   Elfrid Payton   New York Knicks Wed, Oct 30, 2019   Day To Day (Hamstring) - The Knicks have listed Payton Jr. as OUT for Wednesday's game (Oct. 30) against the Magic.
>   Elfrid Payton   New York Knicks Thu, Oct 31, 2019   Day To Day (Hamstring) - Payton is listed as out for Friday's (Nov. 1) game against Boston.
<   Enes Kanter Boston Celtics  Wed, Oct 30, 2019   Day To Day (Left Knee) - The Celtics have listed Kanter as OUT for Wednesday's game (Oct. 30) against the Bucks.
>   Enes Kanter Boston Celtics  Thu, Oct 31, 2019   Day To Day (Left Knee) - The Celtics have listed Kanter as OUT for Friday's game (Nov. 1) against New York.
<   Evan Turner Atlanta Hawks   Wed, Oct 30, 2019   Day To Day (Achilles) - Turner is listed as doubtful for Thursday's (Oct. 31) game.
>   Evan Turner Atlanta Hawks   Thu, Oct 31, 2019   Out (Achilles) - Turner is listed as OUT for Thursday's (Oct. 31) game.
>   Frank Ntilikina New York Knicks Thu, Oct 31, 2019   Day To Day (Neck) - Ntilikina is listed as probable for Friday's (Nov. 1) game.
<   Harry Giles Sacramento Kings    Wed, Oct 30, 2019   Day To Day (Knee) - Giles III was inactive for Wednesday's game (Oct. 30) against the Hornets.
>   Harry Giles Sacramento Kings    Thu, Oct 31, 2019   Day To Day (Knee) - Giles III is listed as questionable for Friday's (Nov. 1) game.
<   Jaylen Brown    Boston Celtics  Wed, Oct 30, 2019   Day To Day (Illness) - Brown is listed as OUT for Wednesday's (Oct. 30) game against the Bucks.
>   Jaylen Brown    Boston Celtics  Thu, Oct 31, 2019   Day To Day (Illness) - Brown is listed as questionable for Friday's (Nov. 1) game against New York.
>   Justise Winslow Miami Heat  Thu, Oct 31, 2019   Out (Lower Back) - Miami Heat F Justise Winslow is OUT for Thursday's (Oct. 31) game against Atlanta with lower back stiffness.
>   Kawhi Leonard   Los Angeles Clippers    Thu, Oct 31, 2019   Out (Load Management) - Los Angeles Clippers F Kawhi Leonard is out for Thursday's (Oct. 31) against San Antonio.
>   Kyle Korver Milwaukee Bucks Thu, Oct 31, 2019   Out (Rest) - Korver is listed as OUT for Friday's (Nov. 1) game.
>   Matthew Dellavedova Cleveland Cavaliers Thu, Oct 31, 2019   Out (Personal) - Dellavedova is listed as OUT for Friday's (Nov. 1) game.
<   Myles Turner    Indiana Pacers  Wed, Oct 30, 2019   Day To Day (Sprained Right Ankle) - Turner left Wednesday's (October 30) game with a sprained right ankle.
>   Myles Turner    Indiana Pacers  Thu, Oct 31, 2019   Out (Sprained Right Ankle) - Turner is week-to-week with a sprained right ankle.
<   Rajon Rondo Los Angeles Lakers  Tue, Oct 29, 2019   Day To Day (Calf) - Rondo did not play in Tuesday's game (Oct. 29) against the Grizzlies.
>   Rajon Rondo Los Angeles Lakers  Thu, Oct 31, 2019   Day To Day (Calf) - Rondo is listed as out for Friday's (Nov. 1) game against Dallas.
<   Sekou Doumbouya Detroit Pistons Wed, Oct 30, 2019   Day To Day (Concussion) - The Pistons have listed Doumbouya as OUT for Wednesday's game (Oct. 30) against the Raptors.
>   Sekou Doumbouya Detroit Pistons Thu, Oct 31, 2019   Out (Concussion) - The Pistons have listed Doumbouya as OUT for Friday's (Nov. 1) game.
>   Will Barton Denver Nuggets  Thu, Oct 31, 2019   Out (Left Toe) - Denver Nuggets G Will Barton is OUT for Thursday's (Oct. 31) game against New Orleans with left toe inflammation.
bash awk gnu uniq
1个回答
1
投票

经过一番苦恼之后,我想到了这个。它计算第二个字段的所有出现次数,然后打印等于1的那些出现。

awk -F $'\t' '{count[$2]++} count[$2] == 1'
© www.soinside.com 2019 - 2024. All rights reserved.