Searching for specific filenames


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching for specific filenames
# 1  
Old 05-17-2010
Searching for specific filenames

Hi

I would like to know how to search through a directory and pull out files that has a specific pattern in the filename. For example if the filename has "bsc" in it, then that file must be moved to another directory where I will perform some operations on it. I know grep can be used, but I'm not certain of how to use it.

Thanks
# 2  
Old 05-17-2010
Code:
for filename in `ls *bsc*`;
do
    cp $filename /PATH/
done

# 3  
Old 05-17-2010
Quote:
Originally Posted by amitranjansahu
Code:
for filename in `ls *bsc*`;
do
    cp $filename /PATH/
done

why exactly do you need an 'ls'?
# 4  
Old 05-17-2010
My filename is gen_bsc_orig_001.csv
I want to look for all filenames that have this pattern: "_bsc_"
And then process these files
The above says :
Code:
$ ./Import_PlannedBSC.sh -b
ls: bsc: No such file or directory

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 05-17-2010 at 08:52 AM..
# 5  
Old 05-17-2010
Did you try
Code:
find . -type f -name "*_bsc_*" -exec mv {} /path/to/another/dir \;

# 6  
Old 05-17-2010
This is my results:

Code:
$ ./Import_PlannedBSC.sh -b
find: missing argument to `-exec'



---------- Post updated at 08:07 AM ---------- Previous update was at 07:58 AM ----------

This works:

Code:
for filename in "*_bsc_*";
do
cp $filename $dsxdir 
done



Last edited by pludi; 05-17-2010 at 10:05 AM..
# 7  
Old 05-17-2010
All right, it looks like your problem is solved Smilie
Else I'd have suggested to make a copy of your production directory and try to run the find command directly from shell there. If it worked, than we could concentrate on your .sh script, which seemed to fail.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching range of filenames witn and without numbers on the end

So I'm grepping for the following right now: ls -la /somedirectory/*.log* | awk '{print $9}' The problem with this is that I get the following output: /somedirectory/errors_1_foo.log /somedirectory/errors_1_foo.log.1 /somedirectory/errors_1_foo.log.2... (4 Replies)
Discussion started by: LinuxRacr
4 Replies

2. Shell Programming and Scripting

Searching same filenames in different partitions

Hi, We are doing some migration work. The same files may exist in different partition/mountpoints. We may place it in a single place, hence we don't want any duplicates...we will rename the file names if we know the files which has duplicates(by file name)). It would be nice if a script... (3 Replies)
Discussion started by: saravanapandi
3 Replies

3. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

4. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

5. UNIX for Dummies Questions & Answers

Searching by date range from filenames

Hello all, i have tons of files in folder named like this (yyyymmdd): bookcollection20100729 bookcollection20100730 bookcollection20100731 bookcollection20100801 bookcollection20100802 etc. I need to find files with date range in there names lets say from 2010.07.30 - 2010.08.02 ... (10 Replies)
Discussion started by: Whit3H0rse
10 Replies

6. Shell Programming and Scripting

Finiding filenames with specific index string

Hi All, I have a file (Names.txt) and the contents of the file is give below. $ cat Names.txt FF313207008.txt FF223207007.txt FF143207006.txt FF372150600.txt FF063407005.txt FF063307005.txt $ From these given file names I want to find the files which has the 6th index value as 2. So... (5 Replies)
Discussion started by: krish_indus
5 Replies

7. UNIX for Advanced & Expert Users

Searching filenames containing certain text???

Suppose there are multiple files containing certain text "abc". How to print the name of all such files with a single command from unix prompt? Thanks in advance (6 Replies)
Discussion started by: skyineyes
6 Replies

8. Shell Programming and Scripting

Grepping for filenames containing value in specific segment within file

I am trying to grep for filenames containing a specific value within a particular segment. The lines containing the segment I'm looking through reads like "HL^1^^1^1", "10^9^9^0", and "HL^11^4^8^1". I would like to find the data that contains only the number nine after the third caret where the... (4 Replies)
Discussion started by: HLee1981
4 Replies

9. Shell Programming and Scripting

searching for filenames with search strings in another file

Hi, I have 5 files in a directory. emp1_usage.txt emp2_usage.txt emp3_usage.txt emp4_usage.txt emp5_usage.txt I am using sqlldr to get the contents of the above 5 files and store it in a temp table and update my original table using temp table. for f in *emp*.txt do sqlldr... (3 Replies)
Discussion started by: pathanjalireddy
3 Replies

10. Shell Programming and Scripting

Searching for a specific string in an argumnet

I want to check the second argument for a specific string . The code below is what I am trying, but I get: UX:test (./test): ERROR: { if ($0 ~ /StringImLooking4/) {print $1} }: Unknown operator I want to test if the second argument contains the string StringImLooking4 Unixware 7 ... (1 Reply)
Discussion started by: dinplant
1 Replies
Login or Register to Ask a Question