Quantcast
Viewing latest article 11
Browse Latest Browse All 31

Answer by ozzy for Unix command to search with a string of 6 numbers for any 3 matching numbers per line

Assuming that you have a file named file that contains lines with mutually different whitespace-separated numbers, and you have a set of 6 numbers - e.g. 38, 39, 40, 41, 42, 43 - that you want to search for in combinations of three, such that lines that consecutively contain three of these numbers in random order are listed as a result of the search, you could use:

grep -P  '((^|\s+)(38|39|40|41|42|43)(?=($|\s))){3}' file

which uses grep with a Perl regular expression (PCRE).


Viewing latest article 11
Browse Latest Browse All 31

Trending Articles



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