So the final process I would like to achieve is:
find all files with this string smbprn_000_Microsoft_Word_-_OriginalFile.pdf
remove the smbprn_*_Microsoft_Word_-_part
append the file creation date onto the end of the filename: OriginalFile_DD_MM_YY.pdf
Move the file to a new location.
This can be in any order, I suspect moving the files to a new location first would be the best option not sure about the rest?
Was thinking of using this:
I'm afraid I didn't really pay attention to what you were trying to do when I noticed that your script was missing the semicolon and just pointed out that adding the semicolon would get around the syntax error.
Looking at what you've come up with so far, I note that some of the things you're doing rely on features that are not portable (assuming that read with no operand will store the line read in the shell variable REPLY and depending on the ${var/.../...} variable expansions), or may be overly complex (using find if all of the files you want to process are in the current working directory). The following scripts don't depend on anything that is not required by the POSIX standards and the Single UNIX Specification, and they also add in the current date in the new names of the files in the format requested. (Both of these also include "echo" to verify that the commands that they execute will do what you want. If one of them does do what you want, remove the "echo " to actually rename the files.) As RudiC noted, the date supplied here will be the date when the file is renamed; not the date when the file was created.
First, if all of the files you want are in the current directory, try the following:
I use the Korn shell, but these scripts will work with any shell that behaves as specified by the standards.
Second, if some of the files you want to rename are in subdirectories try the following:
If you want all of the renamed files to be moved to the current directory instead of leaving them in the directory where they were found, change:
in the above script to:
or if you want to move all of the files to another (single) directory:
As long as you leave in the echo until confirm that one of these scripts does what you want, I don't think you need the cp. You could also turn the echo into a prompt showing that mv that is about to be executed and force the person running the script to reply "yes" to execute the mv command or "no" to skip the rename.
How do I write the command to find all files with any lower case letters in the filename? I have tried
find . -name *\(a-z\) and a lot of combinations like that, without success.
thanks
JP:confused: (4 Replies)
Hi,
I need to write a small script to search in some specific directories to check if any file is present with a unix command name...
Means if the directory contains any files like cat, vi, grep, find etc i need to list those files into a file.
Please help
Thanks,
D (6 Replies)
Hi,
I am having set of files whose names are stored in a file say "filelist.txt"
Now, I want to find all files contained in "filelist.txt" from my parent directory.
Is there any way to let find command understand "filelist.txt" just like we have option -f in awk.
I donot want to run a... (4 Replies)
Hi, guys, I'm not a high-end programmer, but I've been trying to write a script to remove all of the b.rtbn2.cn (and b.adserv.cn and any future variation) injected script tags on the server. (Still working on security fixes to prevent it in the future, just need to clean up now.)
My approach is... (1 Reply)
Hi Gurus,
Do any kind souls encounter have the same script as mentioned here.
Find and compare filenames in different mount point and remove duplicates.
Thanks a million!!!
wanna13e (7 Replies)
I have the following code:
find /usr/local/test5 -type f -mtime +30 -exec ls -l {} \; | awk '{print $5, $6, $7, $8, $9}'
I have this as output:
14 Aug 12 00:00 /usr/local/test5/file1
14 Aug 12 00:00 /usr/local/test5/lastname,
The bolded part is where I run into trouble. The actual... (4 Replies)
I have input file called file1 with characters that have \\ in it.
I cannot change input file, because it is generated earlier in script.
Now would like to replace string on line in file called bfile with output from file1
I have been using sed command.
$cat file1
pc//6sPxp==
$ cat scr1... (4 Replies)
I have a group of files in different directories with characters such as " ? : in the file names. How do I find these files and remove these characters on mass?
Thanks (19 Replies)
Hi,
Can anyone let me know the command to know the list of filenames that have string 31 in their 4th and 5th positions inside the file:
grep -l "31" main*.txt
The above grep lists all the files which have 31 at any position but I want filenames having 31 at position 4 and position 5. (8 Replies)
Hi,
How to change the filenames with timestamp in sub folders
I have the following code to select the records.
find . -type f -name '*pqr*' -ctime 1 -print
The following is the example
app_root_dir="/`echo $ScriptDir | cut -d'/' -f2`"
$app_root_dir/../BadFiles directory
uvw.bad... (3 Replies)