So I have two files that look like this:
file1
userName | cpu% | command | date created
user1 101.6 plasma-de+ Thu Aug 8 09:30:17 MDT 2019
user2 100.0 plasma-de+ Thu Aug 8 09:30:17 MDT 2019
user3 102.0 plasma-de+ Thu Aug 8 09:30:17 MDT 2019
file2
userName | cpu% | command | date created | date updated
user1 101.6 plasma-de+ Mon Aug 5 06:35:39 MDT 2019 Mon Aug 5 06:35:39 MDT 2019
user2 100.0 plasma-de+ Mon Aug 5 06:35:39 MDT 2019 Mon Aug 5 06:35:39 MDT 2019
file2 after command is run
userName | cpu% | command | date created | date updated
user1 101.6 plasma-de+ Mon Aug 5 06:35:39 MDT 2019 Thu Aug 8 09:30:17 MDT 2019
user2 100.0 plasma-de+ Mon Aug 5 06:35:39 MDT 2019 Thu Aug 8 09:30:17 MDT 2019
user3 102.0 plasma-de+ Thu Aug 8 09:30:17 MDT 2019 Thu Aug 8 09:30:17 MDT 2019
I want to take col1 of file1 and if there is a match in col1 of file2, update the "date updated" in the last column. If there is no match, I want to append the entire line of file1 to file2 and append a "date updated" value to that line as well.
I am currently using awk 'NR==FNR{c[$1]++;next};c[$1] > 0' file2 file1
for a baseline comparison, but that wrongly prints the whole line IF there is a match and I also cannot figure out how to add another condition for updating the date column. I am also trying to do this in a shell script.
cp file1 file2
should do the trick.cp file1 file2
is not enough.