Terminal ops: mv to affect multiple objects of container
I believe the best way that the reader and I might quickly develop the understanding I wish to communicate, would be to preview the screen cap featuring a tedious, albeit successful operation (Cygwin, but i doubt it matters):
http://whatsonyourbrain.com/a_genera...uery_re_mv.png Identifying a problem: need to shorten file names, i resorted to that which i presumed would do the job: Cygwin term. And, so it did. MY QUESTION: Certainly there is a more efficient way to have done this, through a more-- perhaps, forgive my poor rhetoric-- /scripted/ approach? E.g. find all files containing the string "... It's the Infectious Grooves ", and remove that string. (vs, as i did, with each individual file, where it was necessary to copy / paste each variation of file names). Thank you for your advisory. Best regards J Sabarese @ajaxStardust www.NoviceNotes.Net |
Somebody may (likely) have better, but to get you started...
Code:
#!/bin/bash Code:
rename-files "Remove this string" |
Great Help. Couple Questions:
Thanks so much for your thoughtful reply, and attention to my concerns. It does not go w/out appreciation.
First: When I look at this, i think... okay,he's doing some sort of regular expression evaluation here. But, i'm unfamiliar w/ the syntax. E.G. $filename, this is a pseudo-name, you've placed for example, yes? Could you please be a bit more specific as to how i would setup the code? Second. Your code-- it is meant for-- something like rename.sh, yes? a shell executable script? assuming i get that far w/ the code i want, is it as simple as [ $> exec rename.sh ] ?? (i'm cheating, i know... but figure i might as well brush-up on my syntax, etc. while i've got your attention) EDIT: OH! wait, /filename/ in your code becomes a variable, referenced subsequently however using the /dollar sign/. it's coming back to me, but i've written only nominal batch scripts for BASH. (uh, this is BASH, yes?) Thanks again, and for your patience. Sincerely. -JS www.ChordsAndScales.Info @ajaxStardust |
This is a shell script.
You save that code to a file, whatever you want to use. I used rename-files as an example. Quote:
Code:
$ ./rename.sh Code:
c:\cygwin\bin\bash.exe rename-sh <arguments> Quote:
$1 is a special variable, the first parameter of the script ($2 the second, $3, and so on). You want to enclose this in strings, to ensure that any string containing spaces is included in the first argument (otherwise the shell parses each peach as a separate string and therefore separate argument, likely not what you want). |
A good cli/bash intro http://rute.2038bug.com/index.html.gz
|
Nearly there, but a still snagging...
per the URL ref'd by @chrism01 , I focused on the following section, albeit a cursory review of the greater resource. http://rute.2038bug.com/node10.html....00000000000000
I believe this /might/ be the section I wish to study, but herein lies my problem; lack of understanding, which goes back to @goumba 's thoughtful, veritable tutorial for me, RE how to process multiple items using MV (or otherwise) as a BATCH script. I am-- at least-- stuck on this concept of Code:
$1 Code:
$filename :sigh: perhaps it's the unfamiliar syntax. Begging your pardon, if a most concrete example were provided (e.g. Filenames VS the BATCH example), I might most easily understand why $filename\\$1 is going to get me what i want to achieve. Sure, I could copy paste your tutorial into my own BATCH file, but that's imitation, not /assimilation/, and I prefer to learn through assimilation, rather than guessing at what's really going on. I suspect the understanding I seek is likely within the reference cited by @chrism01 , but it's a large volume of text which I don't mind reading, but having the advantage of interactive communication, perhaps someone might cite the particular section of that resource which is most applicable to my particular problem. Or, do whatever. I'm easy going, and I truly appreciate your attention to my queries. Many thanks, Sincerely, @ajaxStardust Best regards. |
Code:
mv "$filename" "${filename//$1/}" This line uses bash's own substitution method to move a file (therefore renaming it). "${variable/replacement string/string to find/}". Here, tt does this by taking the variable $filename, a shell script, which contains for example "01 - My Collection - My Artist - My Song 1.flac", and the first parameter passed to the shell script $1 which we'll say contains "My Collection -". The replacement string is empty, so we are replacing "My Collection -" as found in $filename with an empty string, "". So now the new string is "01 - My Artist - My Song 1.flac". And the file is moved to one with the new filename. |
EXTRA! EXTRA! Today's Headline: “ @goumba proves the Simian capable of symbolic Logic!
@goumba,
perhaps not momentarily, but I mean to reference your thoughtful tutorial; your patient itemization of the issues i cited which troubled me. I suspect you're one of the /good ones/. Thank you. I guess one might define himself a geek or a nerd, a dork, whatever if he finds himself eager and excited to try this? Oh, lord! I am a Nerd! hehe... best wishes, friends! Sincerely, Twitter ID: @ajaxStardust Author: ChordsAndScales.Net Be well. Stay well! |
All times are GMT -5. The time now is 10:25 AM. |