Quantcast
Channel: Grep for a line containing only 5 or 6 numbers - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 8

Answer by cuonglm for Grep for a line containing only 5 or 6 numbers

$
0
0

Another perl:

$ perl -MList::Util=first -Tnle '
  s/^\s+|\s+$//g;
  @e = split /\s+/;
  print if @e == 5 || @e == 6 and !first {/\D/} @e;
' file
10      2       12      1       13

Explanation

  • s/^\s+|\s+$//g trim the line.

  • @e = split /\s+/ split the line into array @e.

  • We will print the line if:

    • array @e contains 5 or 6 elements.
    • And None of its elements contain non-digit characters (\D match non-digit characters).

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>