在Bash中两个列表相交 [英] Intersection of two lists in Bash

查看:90
本文介绍了在Bash中两个列表相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个简单的脚本,将列出两个列表中的内容。为了简化,我们用ls作为一个例子。想象一下,一和二​​是目录。


1 =`LS one`
2 =`LS two`
路口$一张价值$的两个

我仍然在bash相当绿色,所以随时纠正我如何我这样做。我只是需要一些命令,将打印出的所有文件中的一和二​​。它们必须存在于两者。你可以称之为一和二​​之间的交集。


解决方案

  COMM -12≤(LS 1) - (LS 2)

I'm trying to write a simple script that will list the contents found in two lists. To simplify, let's use ls as an example. Imagine "one" and "two" are directories.

one=`ls one`
two=`ls two`
intersection $one $two

I'm still quite green in bash, so feel free to correct how I am doing this. I just need some command that will print out all files in "one" and "two". They must exist in both. You might call this the "intersection" between "one" and "two".

解决方案

comm -12  <(ls 1) <(ls 2)

这篇关于在Bash中两个列表相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆