Finding 4 current files having specific File Name pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding 4 current files having specific File Name pattern
# 1  
Old 11-02-2012
Finding 4 different file name inside one folder meeting specific File Name pattern

Hi All,
I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length.
1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number _mm-dd-yyyy-hh-mm-ss-3 Digit Number.data
where ABCJmdmfbsjop :- is alphabet. Each file starts with this ABCJmdmfbsjop alphabet.
7 Digit Number :- Numeric 7 digits.
__:- Underscore character
mm-dd-yyyy-hh-mm-ss :- This will be today's month-date-Year-Hour-Minutes-seconds
-
3 digit number This cauld be any number.
.data:- this will be extension of the file.

For example:- ABCJmdmfbsjop0001552_11-02-2012-13-01-10-962.data

Any help regarding this will be appreciated.
Thanks,
-Lance

Last edited by lancesunny; 11-02-2012 at 01:07 PM..
# 2  
Old 11-02-2012
If your file name is fixed length you can simply use cut:-

Code:
fname="ABCJmdmfbsjop0001552_11-02-2012-13-01-10-962.data"
echo $fname | cut -c 1-13
echo $fname | cut -c 14-20
echo $fname | cut -c 22-40
echo $fname | cut -c 42-44
echo $fname | cut -c 46-50

# 3  
Old 11-02-2012
Hi Bipinath,
Thanks for your help on this.
But the provided solution is not working. Here we are trying to find 4 different file names which are inside one folder and store them into 4 different variable meeting following file name criteria:-
Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number _mm-dd-yyyy-hh-mm-ss-3 Digit Number.data
where ABCJmdmfbsjop :- is alphabet. Each file starts with this ABCJmdmfbsjop alphabet.
7 Digit Number :- Numeric 7 digits.
__:- Underscore character
mm-dd-yyyy-hh-mm-ss :- This will be today's month-date-Year-Hour-Minutes-seconds
-
3 digit number This cauld be any number.
.data:- this will be extension of the file.

For example:- ABCJmdmfbsjop0001552_11-02-2012-13-01-10-962.data

Last edited by lancesunny; 11-02-2012 at 01:06 PM..
# 4  
Old 11-02-2012
Code:
TS=`date +"%m-%d-%Y"`

find . -name "ABCJmdmfbsjop*${TS}*"

---------- Post updated at 11:13 ---------- Previous update was at 11:08 ----------

Code:
find . -name "ABCJmdmfbsjop???????_${TS}*.data"

This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-02-2012
Thanks bipinajith. You solution worked and listed required files.
Now How i can copy these 4 files name listed by find . -name "ABCJmdmfbsjop???????_${TS}*.data" coammnd into 4 variables like Var1, var2, var2 & var4.
Thanks a lot for your help regarding this.
# 6  
Old 11-02-2012
You can use a for loop and use the same cut statement which I provided before for variable assignments:-

Code:
for fname in `find . -name "ABCJmdmfbsjop???????_${TS}*.data" | sed 's/\.\///g'`
do
   # use those cut statements here
done

I hope it help.
This User Gave Thanks to Yoda For This Post:
# 7  
Old 11-02-2012
That's why it is good to get use to use YYYYMMDD_HHMMSS notation so that they get ordered by name naturally
This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

2. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

3. Shell Programming and Scripting

Finding duplicates in a file excluding specific pattern

I have unix file like below >newuser newuser <hello hello newone I want to find the unique values in the file(excluding <,>),so that the out put should be >newuser <hello newone can any body tell me what is command to get this new file. (7 Replies)
Discussion started by: shiva2985
7 Replies

4. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

5. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

6. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

7. Shell Programming and Scripting

finding 0 byte files in current directory only

Hi Gurus, I have a directory A, which has some 0 byte files in it. This directory also has a subdirectory B which also has some 0 byte files in it. The problem: I only need to find out the names of the 0 byte files in the directory A. I'm using the following command find . -name *.zip... (6 Replies)
Discussion started by: ramky79
6 Replies

8. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

9. Shell Programming and Scripting

Finding a specific pattern from thousands of files ????

Hi All, I want to find a specific pattern from approximately 400000 files on solaris platform. Its very heavy for me to grep that pattern to each file individually. Can anybody suggest me some way to search for specific pattern (alpha numeric) from these forty thousand files. Please note that... (6 Replies)
Discussion started by: aarora_98
6 Replies
Login or Register to Ask a Question