0

I'd like to replace extraneous data values (any value >100,000) of a csv with the previous non-extraneous value.

    Input
    1/1/2017 01:00 56242
    1/1/2017 02:00 51214
    1/1/2017 03:00 101442
    1/1/2017 04:00 44242
    1/1/2017 05:00 990919
    1/1/2017 06:00 221512
    1/1/2017 07:00 52100

    Expected Output
    1/1/2017 01:00 56242
    1/1/2017 02:00 51214
    1/1/2017 03:00 51214
    1/1/2017 04:00 44242
    1/1/2017 05:00 44242
    1/1/2017 06:00 44242
    1/1/2017 07:00 52100

Can this be done using awk in a bash script?

Something like:

awk 'BEGIN{FS=OFS=" "} NF{print $1, $2, ($3 >=100000 "not sure") output.csv

Any help would be appreciated - I'm not very familiar with awk.

1 Answer 1

1

awk to the rescue!

awk '{if($NF>100000) $NF=p; else p=$NF}1' file
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, p is what I was missing! Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.