Finding gaps in sequential numbers

后端 未结 6 1091
粉色の甜心
粉色の甜心 2020-12-05 09:31

I don’t do this stuff for a living so forgive me if it’s a simple question (or more complicated than I think). I‘ve been digging through the archives and found a lot of tip

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 10:14

    Perl solution similar to awk solution from StardustOne:

    perl -ane 'if ($F[0] != $p+1) {printf "%d-%d\n",$p+1,$F[0]-1}; $p=$F[0]' file.txt
    

    These command-line options are used:

    • -n loop around every line of the input file, do not automatically print every line

    • -a autosplit mode – split input lines into the @F array. Defaults to splitting on whitespace. Fields are indexed starting with 0.

    • -e execute the perl code

提交回复
热议问题