LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [BASH] Search for 5-digit numbers in document (https://www.linuxquestions.org/questions/programming-9/%5Bbash%5D-search-for-5-digit-numbers-in-document-518173/)

General 01-10-2007 05:56 PM

[BASH] Search for 5-digit numbers in document
 
How can I extract all sets of 5-digit numbers from a file. So anytime the script finds five digits in a group, it adds that number to the list, regardless of what letters are around it. For instance, if it encounters "a15520zuu19991 89123 13a24155" it will list 15520, 89123, and 24155 as 5-digit numbers it found. I am not worried about 6 digit pairs, as running into one is unlikely.

homey 01-10-2007 08:01 PM

Maybe using grep
Code:

grep -o '[0-9]\{5\}' file.txt
or
grep -o '[[:digit:]]\{5\}' file.txt


unSpawn 01-10-2007 08:06 PM

..and a "for" loop for feeding grep the chunks.


All times are GMT -5. The time now is 11:43 AM.