LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-10-2007, 06:56 PM   #1
General
Member
 
Registered: Aug 2005
Distribution: Debian 6.0
Posts: 465

Rep: Reputation: 31
[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.
 
Old 01-10-2007, 09:01 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Maybe using grep
Code:
grep -o '[0-9]\{5\}' file.txt
or
grep -o '[[:digit:]]\{5\}' file.txt
 
Old 01-10-2007, 09:06 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,552
Blog Entries: 54

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
..and a "for" loop for feeding grep the chunks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Docco is boffo for document search LXer Syndicated Linux News 0 05-28-2006 07:03 AM
web document search application for an intranet eantoranz Linux - Software 1 02-13-2006 11:12 AM
can bash generate random digit? sorno Linux - Newbie 5 08-17-2005 07:05 AM
54 digit numbers Scratchit General 3 06-23-2004 10:24 AM
URGENT NEED: floatting numbers in BASH shell grueugene Programming 5 03-12-2004 10:25 AM


All times are GMT -5. The time now is 07:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration