LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2011, 04:19 PM   #1
Quest ion
Member
 
Registered: Oct 2011
Posts: 45

Rep: Reputation: Disabled
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!
 
Old 10-03-2011, 04:25 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Sounds a bit like homework, try 'man bash' then '/Pattern Matching' 'n' to get to the Pattern Matching section.
 
Old 10-03-2011, 05:04 PM   #3
Quest ion
Member
 
Registered: Oct 2011
Posts: 45

Original Poster
Rep: Reputation: Disabled
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..
 
Old 10-03-2011, 05:24 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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'"
 
1 members found this post helpful.
Old 10-03-2011, 07:36 PM   #5
Quest ion
Member
 
Registered: Oct 2011
Posts: 45

Original Poster
Rep: Reputation: Disabled
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!!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: bash file names are different than openbox trash file names whatthefunk Programming 4 02-15-2011 01:52 AM
Extracting File Names from Long Listing of Directory in UNIX Hi_This_is_Dev Programming 15 08-31-2010 11:32 PM
[SOLVED] How to changing same file names by their directory names? bayaraa_u Linux - General 3 04-09-2010 08:26 AM
Bash script for listing FTP usage as the file name of a file created in each share jojothedogboy Programming 1 12-05-2008 03:35 PM
Question Mark appended to the end of file names mts7 Linux - Server 5 09-18-2008 08:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration