I have the following code:
#!/bin/bash
for f in `find . ! -type d`;
do
line=`grep -i 'todo' $f | sed 's/^[ \t]*//'`
if [ $line ]; then
echo "$f:"
echo "$line"
fi
done
but the condition is not working as I would expect it, I need it to only work if something other than an empty string (or nothing) is returned by the command.
Some ideas:
$fin thegrepline to deal with files with spaces in their names.-frather than! -d, otherwise your find may hang on fifos.\tescape didn’t work as a tab match, it consumed a leading t in a test case file line, so I just inserted a raw tab character in the script instead.A slight variation on your script would then be: