LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-17-2010, 07: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, 07:32 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

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

Rep: Reputation: 136Reputation: 136
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 07:35 AM.
 
Old 05-17-2010, 07: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 07:35 AM.
 
Old 05-17-2010, 08:30 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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 08:31 AM.
 
Old 05-17-2010, 09:30 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
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



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

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

All times are GMT -5. The time now is 10:27 PM.

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