Skip to content

Instantly share code, notes, and snippets.

@nullenc0de
Created November 26, 2023 14:28
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 nullenc0de/418309d294dd38d4a89ab6bc517af6a4 to your computer and use it in GitHub Desktop.
Save nullenc0de/418309d294dd38d4a89ab6bc517af6a4 to your computer and use it in GitHub Desktop.
Sort the tlsx output
#!/bin/bash
declare -A companies
while read -r line; do
domain=$(echo "$line" | awk -F'[:[]' '{print $1}' | tr -d ' ')
company=$(echo "$line" | awk -F'[][]' '{print $2}' | tr -d ' ')
if [ -n "$domain" ] && [ -n "$company" ]; then
if [ -z "${companies[$company]}" ]; then
companies["$company"]="{\"name\": \"$company\", \"domains\": [\"$domain\"]}"
else
companies["$company"]=$(echo "${companies[$company]}" | jq ".domains += [\"$domain\"]")
fi
fi
done < data.txt
# Convert associative array to JSON array
json_output="["
for company in "${!companies[@]}"; do
json_output+="${companies[$company]},"
done
json_output="${json_output%,}"
json_output+="]"
echo "$json_output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment