2013-02-15 83 views
0

我在格式为imageN.hd的目录中有几个头文件,其中N是某个整数。这些头文件中只有一个包含文本'trans'。我试图做的是找到哪个图像包含这个表达式使用csh(我需要使用csh为此目的 - 虽然我可以调用sed或perl单行)并显示相应的图像。 show 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的解决方案,但我既

回答

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

优秀的解决方案相当陌生。我需要-i标志,我可以从基本sed中提取数字 – moadeep 2013-02-15 15:13:36