如何从两个列表中删除列表中的目录? [英] How to remove directories in a list from two lists?
问题描述
我正在编写一个 c-shell 脚本,其中我在两个字符串中查找两个不同的目录.我想删除相同的目录的名称.我只想要两者中的唯一目录,而忽略重复的目录.我对如何做到这一点感到有些困惑.
I am writing a c-shell script, where I am grepping two different directories in two strings. I wanted to remove the name of the directories which are the same. I only want the unique directory among the two by leaving out the duplicate ones. I am little confused about how to do this.
sta_views 和 pnr_views 字符串中有一些常见的目录.我使用 ls -l 命令对他们两个进行了搜索,如上所示存储了它们.现在我想要做的是首先我们可以遍历 sta_view 并检查 pnr_view 列表中是否存在它,如果不存在,则将它们放在一个单独的列表中,如果是,则不要做任何事情";希望这有助于您理解我的问题.谢谢!
There are some common directories present in sta_views and pnr_views strings. I am grepped both of them using ls -l command as seen above stored them. Now what I want to do is "first we can loop over sta_view and check if that exist in the pnr_view list and if no , then put them in a separate list , if yes , then do not do anything" Hope this helps to understand you my question. Thank You!
请告诉我这样做的方法,
Please let me know the approach to do it,
set pnr_views = `(ls -l pnr/rep/signoff_pnr/ | grep '^d' | awk '{print $9}'
)`
set sta_views = `(ls -l sta/rep/ | grep '^d' | grep -v common | grep -v signoff.all.SAVEDESIGN | awk '{print $9}'
)`
foreach i ($sta_view)
if [$i == $pnr_view] #just want to remove the list pnr_view from sta_view
then
echo ...
else
此处sta_views
包含存在于pnr_views
中的目录.如何从 sta_views
中删除 pnr_views
目录?
Here sta_views
contains the directories that are present in pnr_views
. How shall I remove the pnr_views
directories from sta_views
?
推荐答案
循环第一个目录中的目录,只需检查第二个目录中是否存在相同的条目.
Loop over the directories in the first directory, and simply check whether the same entry exists in the second.
foreach i ( pnr/rep/signoff_pnr/*/ )
if ( -d sta/rep/"$i:h:t" ) then
switch ("$i:h:t")
case *'common'*:
case *'signoff.all.SAVEDESIGN'*:
breaksw
default:
echo sta/rep/"$i:h:t"
breaksw
endsw
endif
end
Csh 变量修饰符$i:h
返回$i
中文件名的目录名部分,修饰符:t
返回最后一个元素.
The Csh variable modifier $i:h
returns the directory name part of the file name in $i
and the modifier :t
returns the last element from that.
Csh 非常善变,因此现在相当不受欢迎;如果您切换到与 Bourne 兼容的现代 shell,您的运气可能会更好,特别是如果您只是在学习.另请参阅 Csh 被认为有害 以及 https://www.shlomifish.org/open-source/anti/csh/一>.循环 bash 中的值对 展示了如何在重击.
Csh is extremely fickle and thus these days rather unpopular; you might have better luck if you switch to a modern Bourne-compatible shell, especially if you are only just learning. See also Csh considered harmful and the other links on https://www.shlomifish.org/open-source/anti/csh/. Looping over pairs of values in bash shows how to do something similar in Bash.
这篇关于如何从两个列表中删除列表中的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!