gpt4 book ai didi

linux - 在文件列表中查找正则表达式

转载 作者:太空宇宙 更新时间:2023-11-04 09:47:20 25 4
gpt4 key购买 nike

我在一个目录中有几个头文件,格式为 imageN.hd,其中 N 是某个整数。这些头文件中只有一个包含文本“trans”。我想做的是使用 csh 查找哪个图像包含此表达式(我需要为此目的使用 csh - 尽管我可以调用 sed 或 perl 单行代码)并显示相应的图像。显示 iN

这是我最初的简单方法,但不起作用。

#find number of header files in directory
set n_images = `ls | grep 'image[0-9]*.hd' | wc -l`
foreach N(`seq 1 n_images`)
if (`more image$N{.hd} | grep -i 'trans`) then
show i$N
sc c image #this command uses an alias to set the displayed image as current within the script
endif
end

我不确定上述命令有什么问题,但它没有返回正确的图像编号。

此外,我确信还有更优雅的单行 perl 或 sed 解决方案,但我对两者都相当不熟悉

最佳答案

show `grep -l trans image[0-9]*.hd | sed 's/image/i/`

关于linux - 在文件列表中查找正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14897418/

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