我有5000个目录(从ligand_0001到ligand_5000 )。每个包含的子文件名为log.txt,其中包含第2列的分数。我想提取所有这些目录名(ligand_*),这些目录名在第二列中有一个包含-6到-7分数的日志文件。
1 -6.1 0.000 0.000
2 -6.1 2.657 3.713
3 -5.9 26.479 28.383
4 -5.9 27.924 30.549
5 -5.8 4.579 8.657
6 -5.8 26.841 28.725
7 -5.8 25.192 27.089
8 -5.6 3.119 4.640这是ligand_0005文件夹中的子文件(log.txt)。我只想要文件夹的名称,因为它在第2列中包含-6到-7值(即ligand_0005)
发布于 2019-08-08 17:43:24
这是一个小的awk脚本,可以在一次扫描中扫描所有文件。
script.awk
BEGINFILE{ # on every file
pathPartsLen = split(FILENAME,pathParts, "/"); # split path to its parts into arry pathParts
currentDir = pathParts[pathPartsLen - 1]; # find the current parent dir
}
$2 ~ "^-[67]" { # match 2nd field to start with -6 or -7
print currentDir;
nextfile; # skip the rest of the file, goto next file
}运行:
awk -f script.awk $(find ligand_* -name log.txt)解释:
find ligand_* -name log.txt:列出目录ligand_*中的所有log.txt文件
发布于 2019-08-08 16:18:26
使用awk找出第二列中是否存在数字,遍历文件夹并检查每个文件夹的log.txt
ARRAY=()
for i in ligand_*
do
if [[ ! -z $(awk '$2>=-7 && $2<=-6' ${i}/log.txt) ]]
then
ARRAY+=("${i}")
fi
done
printf '%s\n' "${ARRAY[@]}"https://stackoverflow.com/questions/57407694
复制相似问题