2

I have a file that looks like this:

15064 3:30
15401 
15716 
16152 
290 
881 
2048 4:00
2920 

I want check the first value of each line, comparing it with the value of the previous line, and if it is less, print the value of number on the previous line. So the output should be:

16152

Is there a way I can do this with awk?

7

Yes:

awk '$1 < prev { print prev } { prev = $1 }'

This prints prev for every line where the first field is less than the value stored in prev (which is 0 initially), and stores the first field in prev in all cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.