perl to delete consecutive duplicate lines

后端 未结 4 476
感情败类
感情败类 2021-01-21 02:42

I want to delete the consecutive duplicate lines. i.e. for example

**test.txt**
car
speed is good
bike 
slower than car
plane
super fast
super fast
bullet train          


        
4条回答
  •  醉话见心
    2021-01-21 03:23

    Why don't you just use uniq?

    uniq file.txt
    

    Results:

    car
    speed is good
    bike 
    slower than car
    plane
    super fast
    bullet train 
    super fast
    

    You can also do this with awk:

    awk 'line != $0; { line = $0 }' file.txt
    

提交回复
热议问题