Visit Our UNIX and Linux User Community


Finiding filenames with specific index string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finiding filenames with specific index string
# 1  
Old 10-10-2009
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  
Old 10-10-2009
Code:
egrep '^.....2' Names.txt

# 3  
Old 10-10-2009
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  
Old 10-10-2009
Quote:
Originally Posted by scottn
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  
Old 10-10-2009
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  
Old 10-13-2009
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.

Previous Thread | Next Thread
Test Your Knowledge in Computers #155
Difficulty: Easy
Defense Advanced Research Projects Agency (DARPA) initiated the ARPANET, the precursor to the Internet, in 1969.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finiding Files with Perl or awk?

I posted last week about how the find command (known to be slow to begin with), is slowing down by 75x on a windows remote share. Do awk or Perl have the capability to find files (pretty sure the answer for Perl is yes). I want to duplicate find "$dataDir" -type d -name '*.aps' (recursive... (10 Replies)
Discussion started by: Michael Stora
10 Replies

2. Shell Programming and Scripting

Comparing the value of a string index to a variable.

Hi, coding a simple program to compare an entered number to a randomly generated one. The number of digits are restricted so I'm just trying to figure out how to refer to the index value in a string and then compare it to the variable I want. I don't know if bash automatically indexes strings, so... (7 Replies)
Discussion started by: outofcookies
7 Replies

3. Shell Programming and Scripting

awk : search last index in specific column

I am trying to search a given text in a file and find its last occurrence index. The task is to append the searched index in the same file but in a separate column. I am able to accomplish the task partially and looking for a solution. Following is the detailed description: names_file.txt ... (17 Replies)
Discussion started by: tarun.trehan
17 Replies

4. Shell Programming and Scripting

Substitute string with an index number

Objective is to substitute Jan with 01, Feb with 02 and so on. The month will be provided as input. I could construct below awk and it worked. echo Jun | \ awk 'BEGIN{split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",mon," ")}{ for (i=1;i<=12;i++){ if ($1==mon) printf("%02d\n",i)} }' ... (4 Replies)
Discussion started by: krishmaths
4 Replies

5. Shell Programming and Scripting

To cut a string based on last index of identifier

here below is sample string null pointer dereference of 'resourceList' where null is returned from a method/opt/bld/fetch/ds/interzone/notification/LocalLineStatusNotificationListener.java:79 null pointer dereference of 'reList' where null is returned from a... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. UNIX for Dummies Questions & Answers

Reading specific lines from a file using index or keywords

Hello I want to read from a file which contains email addresses. The file format is like this. from@mail.com to1@mail.com to2@mail.com cc@mail.com bcc@mail.com I'll have to read from such file and assign the email addresses to respective variables. frommail =... (11 Replies)
Discussion started by: Kyaw Lwin Phyo
11 Replies

7. UNIX for Dummies Questions & Answers

how to get index/postion of a string?

Hi, I have a string like the following: /db1/data/GLIDER/SYSTEM.dbf need to find the postion where "SYSTEM.dbf" starts, so I tried: LOCATION=/db1/data/GLIDER/SYSTEM.dbf $ expr index $LOCATION SYSTEM expr: syntax error $ expr index "$LOCATION" SYSTEM expr: syntax error ... (5 Replies)
Discussion started by: seafan
5 Replies

8. UNIX for Dummies Questions & Answers

Searching for specific filenames

Hi I would like to know how to search through a directory and pull out files that has a specific pattern in the filename. For example if the filename has "bsc" in it, then that file must be moved to another directory where I will perform some operations on it. I know grep can be used, but I'm... (17 Replies)
Discussion started by: ladyAnne
17 Replies

9. UNIX for Dummies Questions & Answers

string index

I have a line "My name is Deepak" How can i search a string Deepak in the line and find out its index position. Here in this case the result should be 12. (3 Replies)
Discussion started by: dr46014
3 Replies

10. Shell Programming and Scripting

Grepping for filenames containing value in specific segment within file

I am trying to grep for filenames containing a specific value within a particular segment. The lines containing the segment I'm looking through reads like "HL^1^^1^1", "10^9^9^0", and "HL^11^4^8^1". I would like to find the data that contains only the number nine after the third caret where the... (4 Replies)
Discussion started by: HLee1981
4 Replies

Featured Tech Videos