The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
string index dr46014 UNIX for Dummies Questions & Answers 3 09-30-2009 12:18 PM
Find index of last occurence of a character within a string joyan321 Shell Programming and Scripting 5 06-20-2009 12:24 AM
Problem when assign the array with the string index youareapkman Shell Programming and Scripting 4 09-09-2008 05:22 AM
Find first digit in string using expr index jcd Shell Programming and Scripting 4 09-07-2008 12:18 AM
Grepping for filenames containing value in specific segment within file HLee1981 Shell Programming and Scripting 4 08-10-2006 02:12 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2009
krish_indus krish_indus is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 4
Question Finiding filenames with specific index string

Hi All,

I have a file (Names.txt) and the contents of the file is give below.

$ cat Names.txt
FF313207008.txt
FF223207007.txt
FF143207006.txt
FF372150600.txt
FF063407005.txt
FF063307005.txt
$

From these given file names I want to find the files which has the 6th index value as 2. So the needed out put will be as below.

FF313207008.txt
FF223207007.txt
FF143207006.txt

Please help me if there is any command to do that.

Thanks for your help.

Cheers,
Krish
  #2 (permalink)  
Old 10-10-2009
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,662
Code:
egrep '^.....2' Names.txt
  #3 (permalink)  
Old 10-10-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Hi.

Code:
sed -n "/.....2/p" file4 
FF313207008.txt
FF223207007.txt
FF143207006.txt
 
or
 
sed -n "/.\{5\}2/p" file4
FF313207008.txt
FF223207007.txt
FF143207006.txt
( or grep ;-) )
  #4 (permalink)  
Old 10-10-2009
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,662
Quote:
Originally Posted by scottn View Post
Hi.

Code:
sed -n "/.....2/p" file4
or

Code:
sed -n "/.\{5\}2/p" file4
If you don't put a ^ in front of your regex you will also match:

FF313000207011118.txt
FF223100022207007.txt
FF114300999207006.txt
  #5 (permalink)  
Old 10-10-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Yes, of course. Good point, thank you.

In any case the grep solution's the simplest one.

So easy to overlook the simple ones!
  #6 (permalink)  
Old 10-13-2009
krish_indus krish_indus is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 4
Hi Neo,

Thanks for your help. It worked well.

Hi Scott,

Thanks for your help. That also worked well.

As you said, i used egrep, as it is the simple one.

Thanks again.
Krish.
Reply

Bookmarks

Tags
egrep, grep, regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0