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
    #1  
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
    #2  
Old 03-07-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 16 April 2014, 6:21 PM EDT
Location: Saskatchewan
Posts: 18,521
Thanks: 680
Thanked 3,035 Times in 2,855 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
    #3  
Old 03-07-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 16 April 2014, 7:57 AM EDT
Location: NM
Posts: 10,056
Thanks: 250
Thanked 756 Times in 711 Posts
Yes, There are several ways

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

Code:
ls File90

has no errors like that.

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

Code:
ls | grep 'File90$'

If you want files numbered 1000 > 9999:

Code:
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.
    #4  
Old 03-07-2012
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 16 April 2014, 2:21 PM EDT
Location: India
Posts: 1,796
Thanks: 23
Thanked 515 Times in 494 Posts
Quote:
Originally Posted by jim mcnamara View Post
If you want files numbered 1000 > 9999:

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

Reminder:

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


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

Sponsored Links
    #5  
Old 03-09-2012
dodasajan dodasajan is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 8 October 2013, 7:02 AM EDT
Posts: 44
Thanks: 0
Thanked 1 Time in 1 Post
for grep a particular file u can use:

ls |grep "file90"
Sponsored Links
    #6  
Old 03-09-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 2 March 2014, 9:57 PM EST
Posts: 6,393
Thanks: 286
Thanked 670 Times in 641 Posts
@dodasajan
I refer you to post #1 . Your code repeats the original problem but also with a typing error in the name of the file.


Code:
touch File90
touch File900
touch File9000

ls File90
File90

ls | grep 'File90'
File90
File900
File9000

ls |grep 'File90$'
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 08:54 PM.