Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Created December 13, 2015 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhooke/5c0a48c57afe4dba6919 to your computer and use it in GitHub Desktop.
Save kevinhooke/5c0a48c57afe4dba6919 to your computer and use it in GitHub Desktop.
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