LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   File names listing question (https://www.linuxquestions.org/questions/programming-9/file-names-listing-question-906241/)

Quest ion 10-03-2011 04:19 PM

File names listing question
 
I'm learning how to filenames, for instance, all file names starting with 'a', is echo [a]*

All names starting with a and containing three characters, I deduced was [echo]??

All names starting with 'a' but ending with a non a character is echo [a]* | echo *[b-z]

I figured that out but here is where it get's tricky for me, how would one list all filenames that begin with 'a' but not 'aa'?

Then how would one go about creating a file named 'result' that has all the filenames that begin with 'a' but no consecutive 'a'?

Any help would be appreciated!

kbp 10-03-2011 04:25 PM

Sounds a bit like homework, try 'man bash' then '/Pattern Matching' 'n' to get to the Pattern Matching section.

Quest ion 10-03-2011 05:04 PM

I've read that but when i try for instance,

echo [^aa]* it returns,

faa gaaa hah iaia jja

Then when I try and pipe, such as,

echo [a]* | echo [^aa]* is outputs the same as above, which is not what I'm looking for since there are other files such as a, etc..

kbp 10-03-2011 05:24 PM

Quote:

how would one list all filenames that begin with 'a' but not 'aa'?
Code:

echo a[^a]*
Within the '[]', '^' means not. So the command above means "'starting with an a' followed by 'not an a' followed by 'anything'"

Quest ion 10-03-2011 07:36 PM

Ah! For some reason I assumed I had to use pipe, as I'm sure you notice, this is all new to me, but interesting at the same time, thanks!!


All times are GMT -5. The time now is 09:19 AM.