Checking files in folder using starting string for filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking files in folder using starting string for filename
# 1  
Old 07-20-2011
Checking files in folder using starting string for filename

Hi,

How do i check if there are any files present in the folder with some specific starting string.

For eg :- I have used this where Source_File is filename parameter.

Code:
if [ ! -r ${SOURCE_FILE} ]
  then
  return 2
  fi


But in my case the source file name is not constant. The only constant thing is that files with starting string 'XX_IN*' are to be searched.

Please help Smilie

Chetan

Last edited by joeyg; 07-20-2011 at 10:53 AM.. Reason: Please wrap CodeTags around scripts and data
# 2  
Old 07-20-2011
Question Please clarify...

Code:
Folder1
  FileA
  DoorB
  DoorC
Folder2
  DoorD
  DoorE
Folder3
  FileB
  FileC
Dir1
  FileD
  DoorF

Assuming the above names and structure, what exactly are you trying to do?
Please note that
Folder and Dir names are for the various folders.
File and Door names are the respective filenames.

So, for instance, are you trying to find all filenames that begin "File" in any directory or only those named "Folder"?

If I have this all wrong, please clarify with examples.
# 3  
Old 07-20-2011
Yes, exactly...! I want to search in Folder and count if there are any files with files with filename like FILE* Smilie
# 4  
Old 07-20-2011
Could you do
Code:
find . -name "*.* | grep "File"

or
Code:
find .Folder -name "*.* | grep "File"

This User Gave Thanks to joeyg For This Post:
# 5  
Old 07-20-2011
go to that folder and try this command

ls | grep 'XX_IN*'

Thanks,
Pragyan
This User Gave Thanks to prarat For This Post:
# 6  
Old 07-20-2011
Code:
ls | grep "^SOME"    # start with ...
# =
ls SOME*
# =
echo SOME*
# =
find . -depth 1 -name "SOME*"

This User Gave Thanks to kshji For This Post:
# 7  
Old 07-21-2011
Thanks a lot all of you.

This solution finally worked for me...... Here I find and count the number of files matching the start string....!!

Code:
ls -l |grep 'XX_GT'| wc -l

Cheers Smilie

Last edited by radoulov; 07-25-2011 at 06:31 AM.. Reason: Code tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Renaming files by appending string from within file to filename

Greetings. I am working in a Linux environment and am trying to figure out a way to rename files in a directory by appending a unique strings that appears within a certain area in those files. I have gotten as far as identifying what that particular unique string is with a command like the... (10 Replies)
Discussion started by: HLee1981
10 Replies

2. Shell Programming and Scripting

Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All, Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days. That means files created with that prefix, today or yesterday, shouldn't be removed. Thanks, Dev (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

3. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

4. Shell Programming and Scripting

Bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

5. Shell Programming and Scripting

URGENT!!! bash script to sort files into folder according to a string in the filename

Hi all. I am very new to linux scripting and i have a task i can only solve with a script. I need to sort files base on the date string in their filenames and create a folder using the same date string then move the files to their respective folders. Scenario: Folder Path:... (1 Reply)
Discussion started by: ace47
1 Replies

6. UNIX for Dummies Questions & Answers

Script for checking the files in a folder

Hi , I am using the below script for checking for a file in a folder. if ; then echo 0 else echo 1 fi Is there any way we can check for files which are starting with GL*.csv.What I am trying to do is , I have to check in a folder for the GL*.csv files if there are any files they I... (6 Replies)
Discussion started by: wangkc
6 Replies

7. UNIX for Dummies Questions & Answers

Jar/Tar to a diffent folder/same folder w/ filename

Hi, I want to extract myfile.war to a folder which is in the same folder with war file.I did this as normal: jar -xvf myfile.war But it exploded all the content of file to the same level folder instead of that I was expecting to create a folder called myfile. This works with tar: ... (0 Replies)
Discussion started by: reis3k
0 Replies

8. Shell Programming and Scripting

Continously checking folder and executing files

Hello All, I want to make a script which continously checks one folder all the time that is there is any file in it or not, and if it found any file in it than execute that file with the following command. apxrcv -text < filename > outputfile Actually my requirement is that i will put... (4 Replies)
Discussion started by: wakhan
4 Replies

9. Shell Programming and Scripting

Replace string in all files in a folder and subfolders.

i need to change string in all files in current folder and all subfolders. i wrote the following script. It works good except it dont delete temp file from subfolders. for z in `find . -type f -name "*.html" -o -name "*.htm"`; do sed -e 's@abc@xyz@g' $z>temp; mv temp $z; done any idea?... (1 Reply)
Discussion started by: crazynups
1 Replies

10. UNIX for Dummies Questions & Answers

checking missing files in side a folder

Dear all, Every hour i am receiving several data files to one folder for 24 hours each day.But some times some hours i do not have the files because of some problem.So i want to check the files inside the folder at the end of the day wether how many files i received in each hour like this.so i... (4 Replies)
Discussion started by: Nayanajith
4 Replies
Login or Register to Ask a Question