Read a file backwords line by line in bash

后端 未结 1 1552
小蘑菇
小蘑菇 2021-01-28 22:25

I need to read my file line by line from the end. I tried tac but that works like cat and I want to access it line by line.

Is there a way to d

相关标签:
1条回答
  • 2021-01-28 23:00

    You can use tac... together with a while loop:

    while IFS= read -r line
    do
       echo "line is: $line"
    done < <(tac file)
    

    Test

    $ seq 5 > a
    $ while IFS= read -r line; do echo "line is: $line"; done < <(tac a)
    line is: 5
    line is: 4
    line is: 3
    line is: 2
    line is: 1
    
    0 讨论(0)
提交回复
热议问题