LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-26-2003, 02:55 PM   #1
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Rep: Reputation: 15
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.
 
Old 06-26-2003, 02:56 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Why not just use find?
 
Old 06-26-2003, 02:58 PM   #3
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
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.
 
Old 06-26-2003, 03:01 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Use the print format:
find /path/to/smoewhere -name blah*.* -printf "%f\n"
 
Old 06-26-2003, 03:03 PM   #5
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Thanks.
 
Old 06-26-2003, 03:22 PM   #6
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
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
 
Old 06-26-2003, 03:44 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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}'
 
Old 06-26-2003, 03:48 PM   #8
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
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.
 
  


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 scripting question ajaye1971 Linux - Newbie 1 11-16-2005 07:29 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
bash scripting question mehesque Programming 2 03-07-2004 01:37 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 10:05 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:32 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