【发布时间】:2022-01-05 02:08:52
【问题描述】:
我想知道是否有一种方法可以在 AIX 6.x 上使用 find 命令搜索某个目录(包括子目录)中的所有文件,然后调用外部命令(例如 hlcat)将它们显示/转换为可读格式,然后可以通过 grep 命令来查找模式,而不是在 shell 中使用循环?
e.g. find . -type f -name “*.hl7” -exec hlcat {} | grep -l “pattern” \;
上面的命令不起作用,我必须使用while循环来显示内容并搜索模式,如下所示:
find . -type f -name “*.hl7” -print | while read file; do
hlcat $file | grep -l “pattern”;
done
同时,这些 HL7 文件已使用圆括号进行重命名,以防止在文件名周围不包含双引号的情况下打开它们。
e.g. hlcat (patient) filename.hl7 will fail to open.
hlcat “(patient) filename.hl7” will work.
简而言之,我正在查找命令中寻找一种简洁明了的单行方法,并使用圆括号名称查看和搜索这些 HL7 文件的内容。
非常感谢, 乔治
附: HL7 原始数据由一条连续的线组成,除非使用 hlcat 等工具将其转换为可行的读取格式,否则无法读取。 在
【问题讨论】:
-
你试过了吗?
find . -type f -name “*.hl7” -exec hlcat {} \; | grep -l “pattern” -
find . -exec a-script-that-encapsulates-the-complex-command {} \;. -
我正在寻找其中包含该模式的文件。当前目录中有这些患者的文件。 bash-4.3$ 找到 . -type f -name "患者.*" -exec hlcat {} \; | egrep -l "Barry|Jolene" (标准输入) (标准输入) ……… bash-4.3$ cat search_patient.sh #!/usr/local/bin/bash hlcat $1 | awk -F"|" '{ if ($1 == "^PID" && ($5 ~ /Barry|Jolene/)) { print FILENAME }}' bash-4.3$ find . -type f -name "* Patient*.*" -exec ./search_patient.sh {} \; # 没有找到这个病人的文件。 bash-4.3$ 它没有找到包含患者的文件。
-
search_patient.sh 如何拾取 find 命令找到的每个文件? find 是否将每个文件作为参数(例如 $1)一一传递给 search_patient.sh?