Created
January 16, 2019 10:41
-
-
Save SuoXC/d4c1d99f8395323e437e61ea85f5f962 to your computer and use it in GitHub Desktop.
use *jq* to filter json logs and convert some data into csv mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pattern="*.log" #change to your file pattern | |
# need to install jq | |
function filter_function(){ | |
file=$1 | |
cat $file |jq -r 'select(.userid==100) |[.userid, .name, .age, .type] |@csv' | |
} | |
files=$(ls $pattern) | |
for file in $files ; do | |
echo "current_file:$file" | |
filter_function $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment