I need to write a shell script that find and print all files in a directory which starts with the string:
Now, I know how to check if a string is in the file, by using:
for f in `ls`; do if grep -q 'MyString' $f; then: #DO SOMETHING fi
but how can I apply this to the first line?
I thought to maybe create a variable of the first line and check if it starts with
#include, but I'm not sure how to do this. I tried the
read command but I fail to read into a variable.
I'd like to hear other approaches to this problem; maybe awk?
Anyway, remember, I need to check if the first line starts with
#include, not if it contains that string.
That's why I found those questions: How to print file content only if the first line matches a certain pattern?
they are not completely helping.