Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bash script - find files matching filename pattern, search first line for matching pattern
#!/bin/bash
for f in `find -E . -regex ".*ext1|.*ext2|.*ext3"`
do
line=$(head -n 1 $f)
if [[ $line =~ TextAtStartOfLine:[[:space:]]*([[:digit:]]+) ]]; then
echo "${BASH_REMATCH[0]}" # print whole match
echo "${BASH_REMATCH[1]}" # print 1st group match
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.