我有一个命令,列出了我们正在备份的所有文件夹的完整8级深度路径。我也有一个枚举系统上所有8级深层文件夹的命令。这两个都作为变量存储在bash脚本中。
我正在尝试将一个带文件1的循环放在一起,并将第一行条目用作if
/ then
/中的变量else
,然后向前移动到文件末尾。
我已经尝试了很多事情,但是超出了我的能力范围,无法提供一个示例,不会使本文的读者感到困惑。
TempFile1=/ifs/data/scripts/ConfigMonitor/TempFile1.txt
TempFile2=/ifs/data/scripts/ConfigMonitor/TempFile2.txt
find /ifs/*/*/backup -maxdepth 4 -mindepth 4 -type d > $TempFile1
isi snapshot schedules list -v | grep Path: | awk '{print $2}' > $TempFile2
list line 1 on $TempFile1
Grep for line 1 within $TempFile2
if result yielded then
echo found
else
echo fullpath not being backed up
fi
grep(1)说:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file
contains zero patterns, and therefore matches nothing. (-f is
specified by POSIX.)
因此,以下应工作:
grep -f patterns_to_match.txt file_to_examine.txt
考虑这种情况的另一种方法是,您可以要求GNU grep向您显示所有匹配项:
echo 'Lines that match a pattern in your pattern file.'
grep -f patterns_to_match.txt file_to_examine.txt
然后向您显示与任何模式都不匹配的所有行:
echo 'Lines that do not match any patterns in your pattern file.'
grep -f patterns_to_match.txt -v file_to_examine.txt
这可能比在Bash中一次在文件中循环浏览更快,更高效。除了GNU grep之外,使用grep可能会或可能不会获得相似的结果。虽然-f和-v标志是由POSIX指定的,但我仅针对GNU grep 2.16进行了测试,因此您的里程可能会有所不同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句