I need to print value from 3rd column when 4th column condition is matched

cat Data.log 

REPLICAT RUNNING RPGUJ3   02:00:12 00:00:06
REPLICAT RUNNING RPGUJ4   00:00:10 00:00:06
REPLICAT RUNNING RPGUJ3_3 01:00:11 00:00:00
REPLICAT RUNNING RPGUJ4_3 00:00:12 00:00:06

I want to print those value from column 3rd , which is having time greater than or equal to 1 hr from column 4th only
output be like :

RPGUJ3
RPGUJ3_3

I tried below to get the output of 3rd and 4th column in single file

cat Data.log | awk '{print $3 "     " $4}' >1.out

cat 1.out 

RPGUJ3      02:00:12
RPGUJ4      00:00:10
RPGUJ3_3    01:00:11
RPGUJ4_3    00:00:12

but i am unable to to print

RPGUJ3
RPGUJ3_3
Asked By: ANW

||

Check the first two digits of $4 are not 00:

awk 'substr ($4, 1, 2) != "00" { print $3; }' Data.log > 1.out

awk can read its own datafiles — no need for cat and a pipeline.

$ cat Data.log
REPLICAT RUNNING RPGUJ3   02:00:12 00:00:06
REPLICAT RUNNING RPGUJ4   00:00:10 00:00:06
REPLICAT RUNNING RPGUJ3_3 01:00:11 00:00:00
REPLICAT RUNNING RPGUJ4_3 00:00:12 00:00:06
$ awk 'substr ($4, 1, 2) != "00" { print $3; }' Data.log > 1.out
$ cat 1.out
RPGUJ3
RPGUJ3_3
$ 
Answered By: Paul_Pedant

Using any awk:

$ awk '$4+0{print $3}' Data.log
RPGUJ3
RPGUJ3_3

Adding 0 to $4 tells awk to convert the string, e.g. 02:00:12, to a number and it does so by first stripping anything after the leading digits, which in this cases is from the first :, so the result is just 2. Then using that resulting number as a condition will be false if the result is 0 , true otherwise, just like in C and many other languages:

$ awk '{print $4, "->", $4+0, "->", ($4+0 ? "true" : "false")}' Data.log
02:00:12 -> 2 -> true
00:00:10 -> 0 -> false
01:00:11 -> 1 -> true
00:00:12 -> 0 -> false
Answered By: Ed Morton
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.