Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中删除重复项_Bash_Shell_Awk - Fatal编程技术网

在bash中删除重复项

在bash中删除重复项,bash,shell,awk,Bash,Shell,Awk,嗨,我想要一个一行从两个文件的密钥对中删除重复项 第5列和第6列是键值对 awk“{print$5”\t“$6}”文件1文件2 |排序 我必须获得以下输出(不带重复项) 只需告诉sort使用第5列和第6列,并使用unique: sort -u -k5,6 file1 file2 只需告诉sort使用第5列和第6列,并使用unique: sort -u -k5,6 file1 file2 只需告诉sort使用第5列和第6列,并使用unique: sort -u -k5,6 file1 fil

嗨,我想要一个一行从两个文件的密钥对中删除重复项

第5列和第6列是键值对

awk“{print$5”\t“$6}”文件1文件2 |排序


我必须获得以下输出(不带重复项)


只需告诉sort使用第5列和第6列,并使用unique:

sort -u -k5,6 file1 file2

只需告诉sort使用第5列和第6列,并使用unique:

sort -u -k5,6 file1 file2

只需告诉sort使用第5列和第6列,并使用unique:

sort -u -k5,6 file1 file2

只需告诉sort使用第5列和第6列,并使用unique:

sort -u -k5,6 file1 file2

假设您希望打印整个输入行(如果不希望,请更新您的问题):

鉴于你的最新问题:

awk '!seen[$5,$6]++' file1 file2
$ awk '{cnt[$0]++} END{for (rec in cnt) if (cnt[rec] == 1) print rec}' file
649963661 3
649963655 8
64963661 3
649963655 3
如果您关心保持输入顺序:

$ awk '!seen[$0]++{recs[++numRecs]=$0} {cnt[$0]++} END{for (recNr=1;recNr<=numRecs;recNr++) if (cnt[recs[recNr]] == 1) print recs[recNr]}' file
64963661 3
649963655 3
649963655 8
649963661 3

$awk'!查看[$0]+{recs[++numRecs]=$0}{cnt[$0]+}END{for(recNr=1;recNr假设您希望打印整个输入行(如果不希望,请更新您的问题):

鉴于你的最新问题:

awk '!seen[$5,$6]++' file1 file2
$ awk '{cnt[$0]++} END{for (rec in cnt) if (cnt[rec] == 1) print rec}' file
649963661 3
649963655 8
64963661 3
649963655 3
如果您关心保持输入顺序:

$ awk '!seen[$0]++{recs[++numRecs]=$0} {cnt[$0]++} END{for (recNr=1;recNr<=numRecs;recNr++) if (cnt[recs[recNr]] == 1) print recs[recNr]}' file
64963661 3
649963655 3
649963655 8
649963661 3

$awk'!seed[$0]+{recs[++numRecs]=$0}{cnt[$0]+}END{for(recNr=1;recNr假设您希望打印整个输入行(如果没有,更新您的问题):

鉴于你的最新问题:

awk '!seen[$5,$6]++' file1 file2
$ awk '{cnt[$0]++} END{for (rec in cnt) if (cnt[rec] == 1) print rec}' file
649963661 3
649963655 8
64963661 3
649963655 3
如果您关心保持输入顺序:

$ awk '!seen[$0]++{recs[++numRecs]=$0} {cnt[$0]++} END{for (recNr=1;recNr<=numRecs;recNr++) if (cnt[recs[recNr]] == 1) print recs[recNr]}' file
64963661 3
649963655 3
649963655 8
649963661 3

$awk'!seed[$0]+{recs[++numRecs]=$0}{cnt[$0]+}END{for(recNr=1;recNr假设您希望打印整个输入行(如果没有,更新您的问题):

鉴于你的最新问题:

awk '!seen[$5,$6]++' file1 file2
$ awk '{cnt[$0]++} END{for (rec in cnt) if (cnt[rec] == 1) print rec}' file
649963661 3
649963655 8
64963661 3
649963655 3
如果您关心保持输入顺序:

$ awk '!seen[$0]++{recs[++numRecs]=$0} {cnt[$0]++} END{for (recNr=1;recNr<=numRecs;recNr++) if (cnt[recs[recNr]] == 1) print recs[recNr]}' file
64963661 3
649963655 3
649963655 8
649963661 3

$awk'!看到[$0]+{recs[++numRecs]=$0}{cnt[$0]+}END{for(recNr=1;recNr试试这个
awk

awk '{ ++a[$5, $6]; b[$5, $6] = $0 } END { for (i in a) if (a[i] == 1) print b[i] }' file
按顺序:

awk '{ key = $5 "|" $6 } !a[key]++ { b[key] = $0; keys[i++] = key } END { for (i = 0; i in keys; ++i) { key = keys[i]; if (a[key] == 1) print b[key] } }' file

试试这个
awk

awk '{ ++a[$5, $6]; b[$5, $6] = $0 } END { for (i in a) if (a[i] == 1) print b[i] }' file
按顺序:

awk '{ key = $5 "|" $6 } !a[key]++ { b[key] = $0; keys[i++] = key } END { for (i = 0; i in keys; ++i) { key = keys[i]; if (a[key] == 1) print b[key] } }' file

试试这个
awk

awk '{ ++a[$5, $6]; b[$5, $6] = $0 } END { for (i in a) if (a[i] == 1) print b[i] }' file
按顺序:

awk '{ key = $5 "|" $6 } !a[key]++ { b[key] = $0; keys[i++] = key } END { for (i = 0; i in keys; ++i) { key = keys[i]; if (a[key] == 1) print b[key] } }' file

试试这个
awk

awk '{ ++a[$5, $6]; b[$5, $6] = $0 } END { for (i in a) if (a[i] == 1) print b[i] }' file
按顺序:

awk '{ key = $5 "|" $6 } !a[key]++ { b[key] = $0; keys[i++] = key } END { for (i = 0; i in keys; ++i) { key = keys[i]; if (a[key] == 1) print b[key] } }' file


为什么这是预期的输出?为什么缺少
649963660 3
?发布一个包含6个或更多字段的实际示例输入文件以及该文件的预期输出,以便我们更好地了解您正在尝试执行的操作。输出中不包括条目649963660 3649963660 3,它是一个重复的键值对。哦,所以您不只是想要若要删除之前出现的后续值,您希望在重复时删除所有值。明白了。我有两个文件,其中包含键值对和其他值。我需要按排序顺序获取非重复键值对。为什么这是预期的输出?为什么
649963660 3
缺失?发布实际的示例输入文件包含6个或更多字段,以及该文件的预期输出,因此我们可以更好地了解您正在尝试执行的操作。输出中不包括条目649963660 3649963660 3,它是一个重复的键值对。哦,所以您不只是希望删除之前出现的后续值,而是希望删除所有val重复时使用。明白了。我有两个文件,其中包含键值对和其他值。我需要按排序顺序获取不重复的键值对。为什么这是预期的输出?为什么缺少
649963660 3
呢?发布一个包含6个或更多字段的实际示例输入文件和该文件的预期输出,以便我们得到一个be我不知道你要做什么。输出中不包括条目649963660 3649963660 3,它是一个重复的键值对。哦,所以你不只是想删除之前出现的后续值,而是想在复制时删除所有值。明白了。我有两个文件,其中包含键值对和其他值d、 我需要按排序顺序获取不重复的键值对。为什么这是预期的输出?为什么缺少
649963660 3
?发布一个包含6个或更多字段的实际示例输入文件以及该文件的预期输出,以便我们更好地了解您尝试执行的操作。输入649963660 3649963660 3不包含在输出,这是一个重复的键值对。哦,所以你不只是想删除之前出现的后续值,你想删除所有重复的值。明白了。我有两个文件,其中包含键值对和其他值。我需要按排序顺序获取非重复键值对。谢谢。这是一个非常常见的错误awk习语,甚至是数组名
seen
。谢谢。这是一个非常常见的awk习语,甚至是数组名
seen
。谢谢。这是一个非常常见的awk习语,甚至是数组名
seen
。谢谢。这是一个非常常见的awk习语,甚至是数组名
seen