gpt4 book ai didi

bash - 在文件中查找内容并使用 Text Wrangler 打开

转载 作者:行者123 更新时间:2023-11-29 09:31:15 25 4
gpt4 key购买 nike

我正在尝试编写一个 bash 脚本,当在文件列表中找到特定脚本时,它会打开一个文件。最终目标是获取 (search-list.txt) 中的每个行项目,搜索所有文件并在 TextWrangler 中打开它(如果它与术语匹配)。

文件列表(search-list.txt)

3.1.3.2
3.1.4.2
4.1.3.1
4.1.4.1
4.1.5.1
4.2.1.1
4.2.2.1
5.1.6.1

脚本

#!/bin/bash

cat ./search-list.txt | while read output

do

for f in $(find ./content/ -type f -name '*.md'); do
if [ ! -z "$(grep " $output " $f)" ]; then
open -a /Applications/TextWrangler.app $f
fi
done

done

最佳答案

这对我有用:

#!/bin/bash

cat ./search-list.txt | while read output
do

for f in $(find ./content/ -type f -name '*.md'); do
if [ ! -z "$(grep -e "title:[[:space:]]$output[[:space:]]" $f)" ]; then
open -a /Applications/TextWrangler.app $f
fi
done

done

关于bash - 在文件中查找内容并使用 Text Wrangler 打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48773550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com