LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-17-2010, 08:28 AM   #1
LadyAnne
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Searching a directory and pulling out filenames with a certain pattern


Hi

I would like to search a specific directory and pull out filenames that have this pattern:
"_bsc_"
Then I want to do some processing and move the file to another directory

Thank you
 
Old 05-17-2010, 08:32 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Man find should help.
 
Old 05-17-2010, 08:33 AM   #3
serafean
Member
 
Registered: Mar 2006
Location: Czech Republic
Distribution: Gentoo, Chakra
Posts: 903
Blog Entries: 13

Rep: Reputation: 122Reputation: 122
find ./ -iname *_bsc_* -exec command ';'

yes, I am proud I finally manage to do some easy find commands and love to share it. But reading the manpage is highly recommended none the less...

Last edited by serafean; 05-17-2010 at 08:35 AM.
 
Old 05-17-2010, 08:34 AM   #4
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
Would this not work:
Code:
for file_name in `ls *_bsc_*`
do
    <do processing here>
done

Last edited by nuwen52; 05-17-2010 at 08:35 AM.
 
Old 05-17-2010, 09:30 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by nuwen52 View Post
Would this not work:
Code:
for file_name in `ls *_bsc_*`
do
    <do processing here>
done
Bad, bad, BAD!

ls is designed to be read by humans, not programs!

Use this instead:

Code:
for file in *_bsc_*
do
    # do stuff here. The variable "$file" contains the filename
done
It will only search the current dir, not go into child dirs recursively.

Last edited by MTK358; 05-17-2010 at 09:31 AM.
 
Old 05-17-2010, 10:30 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Welcome to LQ!

Quote:
Originally Posted by LadyAnne View Post
Hi

I would like to search a specific directory and pull out filenames that have this pattern:
"_bsc_"
Then I want to do some processing and move the file to another directory

Thank you
I'm not going to be as nice as others.

So you've shown us your need! What's your deed?

In the future we will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist.

'How to Ask Questions the Smart Way' would be one link you should look at to help us to help you in the future.

Your a so your excused to make this mistake this time but try in the future to solve or attempt something then if you have problems the above link should aid so as to provide the means to a solution.

Just a few more links to aid you;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking
Virtualiation- Top 10


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
searching pattern in tab delimited file using grep vaibhavs17 Programming 5 03-05-2010 02:02 AM
Searching for a PATTERN in source files RECURSIVELY dsuratman Linux - General 6 11-23-2007 02:51 AM
'ls' .. or something to identify filenames that have a (space)(numeral) pattern rickh Programming 7 05-09-2006 02:51 AM
pattern searching - kindly help hinetvenkat Linux - Software 2 08-09-2005 12:19 AM


All times are GMT -5. The time now is 03:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration