Help with filename pattern matching

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with filename pattern matching
# 1  
Old 06-26-2011
Help with filename pattern matching


I have files in a directory with filenames that match three specific patterns:

1) [AT]*'.L2_LAC'*
2) [AT]*'.L2_LAC_OC'*
3) [AT]*'.L2_LAC_SST'*

I would like to have an "ls" command that will list only files matching the first two patterns. However, if I type:
ls [AT]*'.L2_LAC'*

I will get files that match all three patterns. If I type:
ls [AT]*'.L2_LAC_OC'*

I will only get files that match the second pattern. Neither of these options are acceptable.

An ideal command would list all of the files whose filenames match the pattern [AT]*'.L2_LAC and are NOT followed by 'SST' anywhere in the remainder of the filename, ie. something like:
ls [AT]*'.L2_LAC'*!SST

Any suggestions on how to do that?

Thank you very much.

# 2  
Old 06-26-2011
First, file name expansion is performed by the shell, and not by the ls command, so the place to look for such tricks is the shell manual page.

Try this in Kshell; worked for me in a limited test. Might work in bash, but I'm not a heavy bash user and don't know what it's support for file name expansion is.

ls *([AT]*.L2_LAC*&!([AT]*.L2_LAC_SSL*))

Check out Kshell doc at man/man1/ksh.html man page for a full explanation.

---------- Post updated at 21:04 ---------- Previous update was at 20:59 ----------

Doesn't seem to work in bash; or not the version that I've got installed.
# 3  
Old 06-26-2011
Try this:

% ls *.L*

% find . -maxdepth 1 -type f \! -name '[AT]*.L2_LAC_SST*' -a -name '[AT]*.L2_LAC*' -o -name '[AT]*.L2_LAC_OC*'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

2. Shell Programming and Scripting

Find: filename in every subdirectory matching a pattern

Hi, I have multiple directories built in following manner /app/red/tmp /app/blue/upd /app/blue/tmp /app/green/tmp /app/red/upd /app/green/upd I have filenames having pattern ONE.XXX.dat TWO.ZZZ.dat and so on across the folders listed above My objective is to list all filenames of a... (4 Replies)
Discussion started by: wahi80
4 Replies

3. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

4. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

5. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

6. UNIX for Dummies Questions & Answers

Pattern matching and Printing Filename

Hi, My requirement is to search for a paritcular string from a group of .gz files and to print the lines containing that string and the name of the files in which that string is present. Daily 500 odd .gz files will be generated in a directory(directory name will be in the form of... (4 Replies)
Discussion started by: krao
4 Replies

7. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

8. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444||015236433 0233654|122555||023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444||015236433 0233654|122555||023365433... (4 Replies)
Discussion started by: imas
4 Replies

9. Shell Programming and Scripting

Filename and Pattern matching

Hiiiii every one, I am facing a problem while giving a file name which has space in it. The problem is ... I have to read a file where the set of input files are stored. Now getting that name I have to open the file and i have to extract the name of the user from where it is written like"by... (2 Replies)
Discussion started by: kheyali Mitra
2 Replies

10. Shell Programming and Scripting

Returning filename and matching lines

What I'm trying to do is to search through a list of files, and output the filename, followed by the lines that matched the pattern. I'm matching the string "letters.moreletters" in any one of searched files, and the output I'm trying to get is: program_1.txt 10 dsdsd sdsd dsd... (2 Replies)
Discussion started by: smb_uk
2 Replies
Login or Register to Ask a Question