How to reverse lines of a text file?

后端 未结 9 1060
迷失自我
迷失自我 2021-01-01 10:05

I\'m writing a small shell script that needs to reverse the lines of a text file. Is there a standard filter command to do this sort of thing?

My specific applicatio

相关标签:
9条回答
  • 2021-01-01 10:57

    In this case, just use --reverse:

    $ git log --reverse --pretty=oneline work...master | grep -v DEBUG: | cut -d' ' -f1
    
    0 讨论(0)
  • 2021-01-01 11:02
    :   "@(#)$Id: reverse.sh,v 1.2 1997/06/02 21:45:00 johnl Exp $"
    #
    #   Reverse the order of the lines in each file
    
    awk ' { printf("%d:%s\n", NR, $0);}' $* |
    sort -t: +0nr -1 |
    sed 's/^[0-9][0-9]*://'
    

    Works like a charm for me...

    0 讨论(0)
  • 2021-01-01 11:04
    awk '{a[i++]=$0}END{for(;i-->0;)print a[i]}'
    

    More faster than sed and compatible for embed devices like openwrt.

    0 讨论(0)
提交回复
热议问题