grep specific number from a list of numbers | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    

UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

grep specific number from a list of numbers

UNIX for Dummies Questions & Answers

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 03-07-2012
godzilla07 godzilla07 is offline
Registered User
Join Date: Oct 2010
Last Activity: 9 September 2013, 11:44 PM EDT
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
grep specific number from a list of numbers

Hello. I have 9060 files labelled File1 to File9060. They are in numerical order. When I grep a file eg. File90 it will show me all files that contain the pattern "File90", eg File901 or File9001. I can only get specific files for File1000 or higher. How can I resolve this problem? Is there a command for the specific pattern recognition only?
Sponsored Links
Old 03-07-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 24 July 2014, 12:41 AM EDT
Location: Saskatchewan
Posts: 18,972
Thanks: 747
Thanked 3,140 Times in 2,949 Posts
Please post exactly what you're doing, word for word, letter for letter, keystroke for keystroke. I can't tell what you're doing so don't know why it's going wrong.

You can force grep to print filenames with the -l(filename only) or -H(filename: matching line) options.
Sponsored Links
Old 03-07-2012
jim mcnamara jim mcnamara is offline Forum Staff  
Join Date: Feb 2004
Last Activity: 23 July 2014, 4:36 PM EDT
Location: NM
Posts: 10,153
Thanks: 268
Thanked 781 Times in 731 Posts
Yes, There are several ways

First off ls will match patterns so you do not have to use grep.

ls File90

has no errors like that.

However, since you want grep, use a trailing $:

ls | grep 'File90$'

If you want files numbered 1000 > 9999:

ls | grep 'File[0-9]{4}$'

This gives you any file that has exactly 4 numbers in the last 4 places in the file name.
Old 03-07-2012
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
Join Date: Apr 2009
Last Activity: 21 July 2014, 11:56 PM EDT
Location: India
Posts: 1,816
Thanks: 24
Thanked 519 Times in 498 Posts
Originally Posted by jim mcnamara View Post
If you want files numbered 1000 > 9999:

ls | grep 'File[0-9]{4}$'


man grep
    In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning;

ls | egrep 'File[0-9]{4}$'

Sponsored Links
Old 03-09-2012
dodasajan dodasajan is offline
Registered User
Join Date: Jan 2009
Last Activity: 3 June 2014, 7:29 AM EDT
Posts: 48
Thanks: 0
Thanked 1 Time in 1 Post
for grep a particular file u can use:

ls |grep "file90"
Sponsored Links
Old 03-09-2012
methyl methyl is offline Forum Advisor  
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 672 Times in 642 Posts
I refer you to post #1 . Your code repeats the original problem but also with a typing error in the name of the file.

touch File90
touch File900
touch File9000

ls File90

ls | grep 'File90'

ls |grep 'File90$'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to grep the specific string or user's list from the file rohit22hamirpur Programming 1 07-25-2011 12:11 AM
the smallest number from 90% of highest numbers from all numbers in file Apfik Shell Programming and Scripting 11 05-22-2011 10:54 PM
iterate through list of numbers and print specific lines with awk euval Shell Programming and Scripting 4 09-17-2010 09:47 AM
list all files containing 4 digit number using grep hobiwhenuknowme UNIX for Dummies Questions & Answers 5 08-11-2010 01:10 AM
Getting unique list of numbers using grep tinku UNIX for Dummies Questions & Answers 6 08-12-2009 07:19 AM

All times are GMT -4. The time now is 10:45 AM.