Skip to content

Instantly share code, notes, and snippets.

@settermjd
Created March 31, 2015 14:44
Show Gist options
  • Save settermjd/3f0eb5b87f20f7832472 to your computer and use it in GitHub Desktop.
Save settermjd/3f0eb5b87f20f7832472 to your computer and use it in GitHub Desktop.
Querying with Winston
node winston.query.js | tr "[{:,'" ' ' | tr -s " " | awk '/country/ { print $2 }' | sort | uniq | wc -l | tr -s " "
@settermjd
Copy link
Author

Assuming a log entry of the following, retrieved with node winston.query.js:

{ file: 
   [ { timestamp: '2015-03-03T10:35:07.445Z',
       employment: 'Freelance Technical Writer',
       country: 'Germany',
       languages: [Object] },
     { timestamp: '2015-03-03T10:34:52.387Z',
       employment: 'Freelance Technical Writer',
       country: 'Germany',
       languages: [Object] } ] }

This script firsts strips out the initial [{:,, and passes the remaining text to awk, which strips out everything, except for lines containing ‘country’, and returns the country name. Finally, the list of countries is sorted, the duplicates removed, and the count of each country tallied.

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