LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 05:56 PM   #1
General
Member
 
Registered: Aug 2005
Distribution: Debian 7
Posts: 526

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, 08:01 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

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

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


Reply



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 06:03 AM
web document search application for an intranet eantoranz Linux - Software 1 02-13-2006 10:12 AM
can bash generate random digit? sorno Linux - Newbie 5 08-17-2005 06:05 AM
54 digit numbers Scratchit General 3 06-23-2004 09:24 AM
URGENT NEED: floatting numbers in BASH shell grueugene Programming 5 03-12-2004 09:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration