remove lines in txt file based on pattern

1201 views regex
7

I have a txt file with contents similar to

    value1 has output a123
    a123 has output 90
    value2 has output 100
    value3 has output a133
    a133 has output 50
    value4 has output a223
    a223 has output 100

I want to remove lines that are repeating twice (lines that appear in last word of previous line ) like--

 a123 has output 90
 a133 has output 50
 a223 has output 100

and kept these--

value1 has output a123
value2 has output 100
value3 has output a133 
value4 has output a223

answered question

Welcome to SO. Stack Overflow is a question and answer site for professional and enthusiast programmers. The goal is that you add some code of your own to your question to show at least the research effort you made to solve this yourself.

i tried using awk nf but can't make the proper output.

1 Answer

8

The following awk command will do:

awk '$1!=l{print;l=$NF}' your_text_file

posted this

Have an answer?

JD

Please login first before posting an answer.