Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-26-2003, 03:55 PM
|
#1
|
Member
Registered: Apr 2003
Posts: 87
Rep:
|
bash scripting question
I need to look for files of a certain name (such as: bleh*.*) within a directory and its subdirectories, and if any files have that sort of name (eg: bleh123.out), I need to have those filenames (just the filenames) printed out, one per line. How can that be done?
Thanks.
|
|
|
06-26-2003, 03:56 PM
|
#2
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
Why not just use find?
|
|
|
06-26-2003, 03:58 PM
|
#3
|
Member
Registered: Apr 2003
Posts: 87
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
Why not just use find?
|
But what would I use to have it only print the filenames?
if you use:
find . -name 'bleh*.*'
it prints out the directory structure.
|
|
|
06-26-2003, 04:01 PM
|
#4
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
Use the print format:
find /path/to/smoewhere -name blah*.* -printf "%f\n"
|
|
|
06-26-2003, 04:03 PM
|
#5
|
Member
Registered: Apr 2003
Posts: 87
Original Poster
Rep:
|
Thanks.
|
|
|
06-26-2003, 04:22 PM
|
#6
|
Member
Registered: Apr 2003
Posts: 87
Original Poster
Rep:
|
Is there a way to have it only print everything up to the decimal point in the filename?
So if it finds bleh123.321, it prints out:
bleh123
|
|
|
06-26-2003, 04:44 PM
|
#7
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
There is no print format to do that. The only way I can think of is to use awk. I'm not great with awk but this should work:
Code:
find /path/to/somewhere -name blah*.* -printf "%f\n" | awk -F. '{print $1}'
|
|
|
06-26-2003, 04:48 PM
|
#8
|
Member
Registered: Apr 2003
Posts: 87
Original Poster
Rep:
|
Quote:
Originally posted by david_ross
There is no print format to do that. The only way I can think of is to use awk. I'm not great with awk but this should work:
Code:
find /path/to/somewhere -name blah*.* -printf "%f\n" | awk -F. '{print $1}'
|
Thanks, it works.
|
|
|
All times are GMT -5. The time now is 07:07 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|