bash - Print specific line and if it contains space - replace or print path -
like in title - need find , read through files specific name, check 7th line specific pattern , if found - print path or replace line.
have problem pipe or exec output of awk.
find . -name "meta" -exec awk 'nr==7 && /t/' {} \;
how pipe output of command, or use -exec on it?
change awk script print file name.
find ... -exec awk 'nr==7 && /t/ { print filename }' {} \;
or alternatively use exit code signal result find
find ... -exec awk 'nr==7 { exit($0~/t/) }' () \; -o -ls
you need take care have same exit code if file short; that's why use counter-intuitive nonzero (failure) exit code case when match found.
if want replace line match, sed -i
might both easier , more portable, though gnu awk has --inline
option.
find ... -exec sed -i '7s/.*t.*/foobar/' {} \;
notice need sed -i '' '7s...
on *bsd platforms, including osx (i.e. -i
option requires mandatory option argument; pass empty string not files).
Comments
Post a Comment