2016-05-11 8 views

答えて

1

あなたが再帰的に、チェックしたいディレクトリから、行うことができます。

find . -type f -exec bash -c '[[ $(sed -n '171p' "$1") =~ package ]] && echo "$1"' _ {} + 

これはあなたに彼らの171行目でpackageが含まれているファイル名が表示されます。非再帰的

find . -maxdepth 1 -type f -exec bash -c '[[ $(sed -n '171p' "$1") =~ package ]] && echo "$1"' _ {} + 

例:

私はbarを探しています:

$ cat foo 
foo 
bar 

$ find . -type f -exec bash -c '[[ $(sed -n '2p' "$1") =~ bar ]] && echo "$1"' _ {} + 
./foo 
0
#This will search second line of all the files and grep over them. 
#Pass search pattern as argument. 

pattern=$1 

for file in * 

do 

cat $file |sed -n '2p' |grep $pattern 

done 
関連する問題