Skip to content

Instantly share code, notes, and snippets.

@SuoXC
Created January 16, 2019 10:41
Show Gist options
  • Save SuoXC/d4c1d99f8395323e437e61ea85f5f962 to your computer and use it in GitHub Desktop.
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
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