Quote:
|
Originally Posted by foufoutos thanks for replying Freston but you are not really solving my problem.
your method seems more complicated than mine. |
Well, I'm not trying to solve your problem. I just pointed out the option of parameter substitution as a probable means to solve your problem. I'm sorry if I made it sound complicated. It is how I would approach this matter.
Quote:
|
Originally Posted by foutoutos Can you at least tell me how I can do an ls and save the contents (the file names) in an array? |
I have no idea why you'd want to do that. It's an extra step and unnecessary in my opinion. Also I have no way of knowing if the arrays will be in the same order.
Let's say you have these directories:
~/test
~/test/torrentpics
~/test/websitepics
~/test/results
Now you run: (Untested!!!)
Code:
for i in ~/test/websitepics/* ; do
yearmonth=${i:0:4}
name=${i#*_}
ls ~/test/torrentpics/centerfold-PM19$yearmonth* && echo is $name || echo $i doesn't match
done
See if this gives errors.
What this does is compare all the year&month fields in the website pics to the year&month field in the torrent pics. It'll echo the name field from the website pics below the corresponding torrent pics, thus allowing to see if there are duplicates.
Also, when no match is found, it'll echo the website pic name corresponding to the missing match.
If this works, then you can cp the torrent files to their new location using the yearmonth and name variables you just created to create the new names.
But how to do that depends on how consistent the torrent files are in their naming scheme. If there are inconsistencies or duplicates with slightly different names, then you'll need to iron that out first. You can use the above script to find if such is the case.
EDIT: In retrospect, is this understandable what I wrote? 'cuz I'd hate it if I sound like one of those posters you hear about, the one with an attitude. I'm only learning these bash things myself. And I know sometimes there is a little trick behind a mechanism that makes life easier. Parameter substitution is just the tool for the job IMHO. But the rest of the snippets of scripts I wrote are quick and dirty. Again, I'm not offering a cheap solution, I'm just trying to help you by offering a mechanism that you can use to write something yourself. With some close examples that wont destroy your system.
It's also not the only solution in town. You can sed or grep or awk your way through this. And you can build arrays with output redirection. That might be as easy as:
ls . > array
or as elaborate as giving each file a variable name with an incremental number appended to takings out of it's filename. But as I said, that is an extra step. You only need that if you want to work with items of datasets numbers of times, for example if you want your script to be interactive; you can have it flag mismatches and ask for human input on what to do with them (Abort, Ignore, Fail?) _ (<=blinking prompt)
PS. Welcome to the forums!
