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 Joseph R. for Grep for a line containing only 5 or 6 numbers

$
0
0

I would go with something a little more powerful than grep. This can do it in perl:

perl -ne 'print if s/\d+/$&/g == 5' your_file

The regex substitution replaces all groups of one or more digits (\d+) with themselves ($&): it does nothing. It is used merely for side effect since the s/// operator returns the number of times it managed to substitute for its regex. Thus, the line is printed only if s/// found 5 groups of digits.


Viewing all articles
Browse latest Browse all 8

Trending Articles



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