Thanks for all the replies, I wasn't expecting it to be that complex.
I sort of thought the script might simply search the filename string for the first underscore and delete it plus all the characters before it, then search for (what would then be) the third underscore delete it plus the next 8 characters (since the time stamp is always YYYYMMDD)?
Or am I being too simplistic?
Not at all.
There are several examples here which do exactly that; excluding and/or deleting.
Could you post your version?
That pertains to the RHS of the pipeline, which can be executed in a subshell or in the foreground. The LHS is always executed in a subshell.
This can easily be checked:
This shows that ksh and zsh execute the RHS in the foreground. The RHS in the other shells and the LHS in all shells is executed in a subshell. In bash 4 there is a separate setting (not the default) that can be turned on so that the RHS is also executed in the foreground.
The process id within a subshell cannot be tested with $$. A subshell is a child process that inherits the environment of the parent shell, including the variable $$. Therefore in a subshell of the parent shell, $$ will represent the parent's $$.
The pid of a subshell can still be checked by starting a child process that is not a subshell and checking $PPID:
I used the following script to test:
Again this shows that the RHS of pipelines in ksh and zsh are executed in the foreground, but the rest are not..
Therefore using a pipeline in the file moving loop, earlier in the thread requires (2n+1) or (3n+1) processes including the ones for the mv command (depending on the shell that is used), while using a heredoc/string or parameter expansions leads to (n+1) processes.
Yes; you're absolutely correct.
Of course the standards allow every element of a pipeline to be executed in the current shell execution environment, but none of the current shells are implemented that way.
I have read through the posts as best I can, just a reminder that x, y & z represent variable number so can't be hard coded. One other thing which I should have mentioned is that OS could also be OD in some cases.
For a quick-and-save renaming, I would install "mmv"
and run
if the reference character is #, like in this man page.
If not available for your distro, download+compile mmv.c
These 2 Users Gave Thanks to MadeInGermany For This Post:
I think Scrutinizer's post#11 is a good starting point. Use a glob like ...*_O[SD]_*... and adapt / validate $first and $last against e.g. a date or so.
So I have tried sed:
Nothing really happened so I escaped that
Then I tried the perl script rename
Which remove the _ and the first letter of the surname to look like
So then I tried:
but got
:-/
Gee, I can't possibly guess what might be wrong.
You told us you wanted to rename files whose names were of the form:
and we made suggestions based on that format. Note that the filenames in this format end with a ); not a ).jpg and that makes a HUGE difference in the attempts to limit the patterns and REs used to match just the files you said you want to process.
You could try this (which should work with your original file naming specification with or without a trailing filename extension):
When run in a directory containing the files:
it produces the output:
If it displays the mv commands you want to run, remove the echo shown in red and run the script again to actually rename the files.
If you have other files in this directory that contain exactly six underscores and a pair of parentheses after the last underscore that you want to exclude, we can tighten up the pattern to avoid false matches (if you'll show us the format of the filenames we need to avoid). As written this string will let x, y, and z can be any strings of non-underscore characters.
(This script will use n+2 processes to rename n files.)
Hello friends!
I have a problem with my script. I'm a italian boy. Sorry for my english ehehehehehhe.
I've many files .jpg and I would like rename they in this mode:
I have not files with progressive number e I would like rename with progressive number. Example:
DSC_0012.JPG
DSC_0582.JPG... (7 Replies)
Hi all,
I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to
find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Hi All,
I want to write a script to rename the file in to the incremental order
for example
Original file
filename=/nfs/n1/file1.img
filename=/nfs/n1/file1.img
filename=/nfs/n1/file1.img
filename=/nfs/n1/file1.img
filename=/nfs/n1/file1.img
I want output shpuld be... (4 Replies)
I have the following directories in my home directory,
my scripts
dbmig es
ms_done
my-home
I want my output to look like the following
MyScripts
DbmigEs
MsDone
MyHome
Basically, I want to get rid of spaces,special characters and convert the first letter of each word to uppercase and... (1 Reply)
Hello,
I have this problem.
In a directory I have 4 csv files with this format:
PHOENIX_KM_INTERAZIONI_YYYYMMDD.csv
PHOENIX_KM_TRIPLETTE_YYYYMMDD.csv
NEWCAB_KM_INTERAZIONI_YYYYMMDD.csv
NEWCAB_KM_INTERAZIONI_YYYY_MM_DD.csv
YYYYMMDD: format CURRENT date
I wont rename all files in... (4 Replies)
I wrote a simple script that converts my windows text files to unix, so that I can compare them to different unix files purposes of my project.
win2unix file1.txt file1Win.txt
win2unix file2.txt file2Win.txt
etc
Is there a way to simplify this to:
<while .txt in... (5 Replies)
Hi, i need a bit of help writting a tcsh script which renames all ascii text files in the current directory by adding a number to their names before the extension
so for example, a directory containing the files
Hello.txt
Hello.t
Hello
should have the following changes,
Hello.txt... (2 Replies)
Let me preface this by stating I have absolutely no idea what I'm doing in this arena, but I'm in need of a little help here.
I need to take filenames like this: amwed_0402c-slug~1-cp.jpg
And reduce them to slug~1.jpg
That is, I need to remove the first 12 and last 3 characters. The... (3 Replies)
Have files of the sort 3p1522015.dgn and need to have them renamed to 152201.dgn. Essentially dropping the 1st 2 characters and the last. I'm relatively new to UNIX and uncertain of where to start. I hope this provides enough detail.
Thanks (5 Replies)
Hi All !!!
Is there any solution to get rid of / " * in old files names WITH A SCRIPT
(About 100 Gb of old files)
I know it can be done i just dont know how !
Hope that some one can help
Best R.
Yovel (1 Reply)