Created
November 26, 2023 14:28
-
-
Save nullenc0de/418309d294dd38d4a89ab6bc517af6a4 to your computer and use it in GitHub Desktop.
Sort the tlsx output
This file contains hidden or 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
#!/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