Hi,
I am trying to understand a part of my existing code built by someone else and also try to bring in one more column in the output.
I have two files as below:
CSV file 1:
awk ' BEGIN{ FS=OFS="," } FNR==NR{ arr[$2]=$NF next } { print $1,(($1 in arr)?($NF>arr[$1]?"Previous_Day_File":"Current_Day_File"):"No_Match") } ' file1.csv file2.txt
I want to bring in col 1 from first file as well in my print output.
The script identifies the age of file and categorize as old or new file .
File 1 holds the filename and the interval (last column). File 2 holds the filename and the time difference ( last column which is calculated after current time-last modification time).
Now I just want to add col1 from first file as well in my output.
I don’t know how to do it with awk. But, you can redirect the output to a file, and then change the lines with sed:
awk '
BEGIN{
FS=OFS=","
}
FNR==NR{
arr[$2]=$NF
next
}
{
print $1,(($1 in arr)?($NF>arr[$1]?"Previous_Day_File":"Current_Day_File"):"No_Match")
}
' file1.csv file2.txt > out
while IFS=',' read -r col1 col2 col3
do
sed -i "s/$col2/$col1,$col2/g" out
done < file1.csv
cat out