Reputation: 3
I need to run a repeat command with the different filename to get the header. However, I need to run each file.
dfits *.fit | grep MSBTITLE
Is there any command I can run several files and show the filename and the header I need?
Upvotes: 0
Views: 42
Reputation: 22225
grep
does not know the filename, so you see only the matching lines, but not which file they come from originally. I would in your case write an explicit loop:
for file in *.fit
do
if titleline=$(dfits $file|grep MSBTITLE)
then
echo $file : $titleline
fi
done
Since dfits
already obscures the file name in its output, we store the output from grep into a variable, and if there is a match, output this line together with the file name.
Upvotes: 1