I need a shell script that finds IP addresses from a text file inside a .csv log file, and if it found the results, it'll make a new column on the right side of the csv file, calling it "SUSPICIOUS"
So far, I came up with this command:
cat *.csv | grep --color=always -z -w -f 'list.txt' | sed 's/^/SUSPICIOUS, /' > *.csv
There are 2 problems with this:
It creates SUSPICIOUS column on every row
It creates new column on left side instead of right side
(If I use regular grep expression, it'll only save the results containing those IP addresses, I need every single row of the logs)
Thanks in advanced for taking your time to read this and helping out.
This seems like it would be much easier to do with
awk
. Load the text file into the keys of an associative array. Then read the CSV file, and test whether the IP field is contained in the array.This uses the inplace extension of GNU awk so it can write the result back to the input file.