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
# 8  
Old 07-25-2011
Now I find the no. of files and display the count. How can I display the maching filenames in display?? :S

---------- Post updated at 02:21 PM ---------- Previous update was at 01:40 PM ----------

Can someone pls help me printing the filenames that match the search criteria?
# 9  
Old 07-25-2011
you want to display the file names along with the count,or you only want the matching file names

if you only want the matching file names then this is enough

Code:
ls | grep 'XX_ID*'


Last edited by radoulov; 07-25-2011 at 06:32 AM.. Reason: Code tags!
# 10  
Old 07-25-2011
Thanks. Yes this was what i was trying to do. Now i have done picking up the filenames and renaming all of them in a loop.

Code:
i=0
for file in `ls |grep "$filename"`
do 
echo "$file"
echo $i
i=`expr $i + 1`
mv /var/tmp/akk2/${file} /var/tmp/akk2/${file}_${i}
done


Last edited by radoulov; 07-25-2011 at 06:51 AM.. Reason: Code tags!
# 11  
Old 07-25-2011
Folks

I have a very quick question. Is there any way that I can list out all the common files with the directory name. Say for example

/home has test1 test2 test3 directories
where test1 has the files named "ABC" "DEF"
test2 has the files named "EFG" "ABC"
test3 has the files named " BC"

For this i have a common file ABC which is present in test1 and test2 directories. Instead of searching each and every directory, i need to get those 2 files to be displayed with the directory name at the root directory itself. Can someone help me out in this regard.

Any help wud be greatly appreciated. Thanks
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