user1983916
user1983916

Reputation: 87

tail to awk pipe do not append if exists in file

Edit: Instead of tossing out the duplicate data I want it to "overwrite" the duplicate data, meaning leave the data but update the timestamp

Problem 1:

I have a command line as follows,

tail -f /some/file.log | awk '$2>10 (if (!($1 in a)) print $1, strftime("%Y-%m-%d %H:%M:%S"); a[$1]=1 ;system("")}' > /some/filteredfile.log

However, I would like the output from this to only add the text to file if it isn't already there (in the 1st column), and if it is there, update the timestamp (in the second column)

Upvotes: 0

Views: 213

Answers (2)

PradyJord
PradyJord

Reputation: 2160

One problem two part may be:

tail -f file.txt | awk -v date="$(date +"%Y-%m-%d-%h%m%s")" '$2>10 {print date, $1; system("")} ' > output.log

It should solve your 2nd part, working for me.

Upvotes: 0

anishsane
anishsane

Reputation: 20980

Try:

tail -f /some/file.log | awk ' $2>10 {if (!($1 in a)) print $1; a[$1]=1; system("")}' > /some/filteredfile.log

Upvotes: 1

Related Questions