Sample Header Ad - 728x90

Returning lines from a JSON log file which contain IP and timestamps read from a CSV file?

-1 votes
1 answer
64 views
so I'm new to Shell Scripting and could use some help. So in my CSV file, I want to see if IP and timestamp values exists in some way in the line entries of the JSON log file, and if so, return that specific JSON log entry to another file. I tried to make it universal so it's applicable to all IP addresses. Here's what the sample CSV file would look like; "clientip,""destip","dest_hostname","timestamp" "127.0.0.1","0.0.0.0","randomhost","2023-09-09T04:18:22.542Z" A sample line entry from the Json Log File {"log": "09-Sept-2023 rate-limit: info: client @xyz 127.0.0.1, "stream":"stderr", "time": 2023-09-09T04:18:22.542Z"} It's the lines from the JSON log file we want to return in the output.txt file when there's a match. The JSON file doesn't have the same fields and organization like the CSV does (with clientip, destip, dest_hostname, timestamp, but I was hoping that I could still at least return lines from the JSON log files to a new file that had matches on the clientip (like we see here with 127.0.0.1 in "info: client @xyz 127.0.0.1) and maybe the timestamp. I've tried join file.csv xyz-json.log > output.txt I've also tried the awk command to no avail. I would really appreciate your help with this!
Asked by Linuxnoob (1 rep)
Nov 30, 2023, 02:11 AM
Last activity: Nov 30, 2023, 11:13 AM