Finding File Names Ending In 3 Random Numerical Characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding File Names Ending In 3 Random Numerical Characters
# 1  
Old 05-04-2011
Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows
CC10-1234P1999.WGS84.p190
each of this files is in a directory named for the file but excluding the extension.

Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to move some of them to a seperate directory, the ones I need to move will be within a defined range, eg I would want to move everything from the file ending in 005 to the file ending in 155.
Any thoughts ?
# 2  
Old 05-04-2011
try:
Code:
 echo **/* |xargs -n1 |while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done


Last edited by yinyuemi; 05-04-2011 at 09:11 PM..
This User Gave Thanks to yinyuemi For This Post:
# 3  
Old 05-04-2011
Thanks mate, do youthink that could be done just using find to get all the .p190 files then setting variables to get the 005 to 155 files ?
# 4  
Old 05-04-2011
if the filename has the unifom format as *.*.*, you can try:

Code:
 echo **/*.*.p190 |xargs -n1 |while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done

if not, try:
Code:
 echo **/* |xargs -n1 |grep '\.p190$'|while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a string in a list of files, print file names

I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string... In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies

2. Shell Programming and Scripting

Finding size of files with spaces in their file names

I am running a UNIX script to get unused files and their sizes from the server. The issue is arising due to the spaces present in the filename/folder names.Due to this the du -k command doesn't work properly.But I need to calculate the size of all files including the ones which have spaces in them.... (4 Replies)
Discussion started by: INNSAV1
4 Replies

3. Tips and Tutorials

How to manage file names with special characters

One of the common questions asked are: how do i remove/move/rename files with special (non-printable) characters in their name? "Special" doesn't always mean the same. As there are more and less special characters, some solutions are presented, ranging from simple to very complicated. Usually a... (0 Replies)
Discussion started by: bakunin
0 Replies

4. UNIX for Dummies Questions & Answers

finding and moving files based on the last three numerical characters in the filename

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190, all in one directory. Now the last three numeric characters, in this case 999, can be anything from 001 to 999. I need to move some of them to a seperate directory, the ones I need to... (5 Replies)
Discussion started by: roche.j.mike
5 Replies

5. Shell Programming and Scripting

Finding consecutive numbers in version names on a txt file

Hi all. I have a directory which contains files that can be versioned. All the files are named according to a pattern like this: TEXTSTRING1-001.EXTENSION TEXTSTRING2-001.EXTENSION TEXTSTRING3-001.EXTENSION ... TEXTSTRINGn-001.EXTENSION If a file is versioned, a file called ... (10 Replies)
Discussion started by: fox1212
10 Replies

6. Shell Programming and Scripting

Finding tags in file names using csh

I have the following script and want to check if in each $f there exists either a "drw" or "smp" tag in the file name. How can I do it? For example npt06-32x24drw has the "drw" tag npt06-32x24smp has the "smp" tag npt06-32x24 no "drw" or "smp" tag found #!/bin/csh set iarg = 0... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

8. Shell Programming and Scripting

Finding missing sequential file names

So, I've got a ton of files that I want to go through (ie something like 300,000), and they're all labeled sequentially. However I'm not 100% positive that they are all there. Is there any way of running through a sequence of numbers, checking if the file is in the folder, if not appending it... (2 Replies)
Discussion started by: Julolidine
2 Replies

9. Shell Programming and Scripting

Weird Ascii characters in file names

Hi. I have files in my OS that has weird file names with not-conventional ascii characters. I would like to run them but I can't refer them. I know the ascii # of the problematic characters. I can't change their name since it belongs to a 3rd party program... but I want to run it. is there... (2 Replies)
Discussion started by: yamsin789
2 Replies

10. Shell Programming and Scripting

Replace characters in all file names in a particular directory

Hi, I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm... For example: bdw0110137.sh should be fdm0110137.sh Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies
Login or Register to Ask a Question