Skip to content

Instantly share code, notes, and snippets.

@schnell18
Last active December 27, 2015 01:29
Show Gist options
  • Save schnell18/7245427 to your computer and use it in GitHub Desktop.
Save schnell18/7245427 to your computer and use it in GitHub Desktop.
find 8-digit named SQLite databases under current directory and run SQL and redirect the result to individual files. The gist demonstrates the use of regex in find command.
for db in $(find . -regextype posix-extended -regex '.*\<[0-9]{8}$' | cut -d'/' -f2-)
do
cat << EOF | sqlite3 $db > $db.dates
select distinct date(login_time, 'unixepoch') login
from login_record
;
EOF
done
@schnell18
Copy link
Author

The [0-9] is used instead of \d because \d is not supported by find. The -regextype posix-extended is also required as the repetition modified {8} is an extended feature which is enabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment