Create a list of files from alias by script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a list of files from alias by script
# 1  
Old 03-31-2018
Create a list of files from alias by script

Actually I have many pictures with diferent name and size around 2000, I need generate a copy of them from one list of alias. The structure of the list is something like this:

alias_list.txt
Code:
<01>randomname.png<02>
Randomname.png
RandoMname.png
RandOmname.png
RandomnamE.png
<01>test.png<02>
<01>fooo.png<02>
foOo.png
<01>bear.png<02>
beaR.png
bEar.png
BEar.png
beAR.png
bEAR.png
BEAr.png
BEAR.png
BEAr.png
.
.
.

The file between <01> <02> is real, I already have it, all files are inside one folder called pictures, I need generate all alias, so I am trying to make one script like this:

alias.txt
Code:
cp /pictures/randomname.png /pictures/alias/Randomname.png
cp /pictures/randomname.png /pictures/alias/RandoMname.png
cp /pictures/randomname.png /pictures/alias/RandOmname.png
cp /pictures/randomname.png /pictures/alias/RandomnamE.png
cp /pictures/fooo.png /pictures/alias/foOo.png
cp /pictures/bear.png /pictures/alias/beaR.png
cp /pictures/bear.png /pictures/alias/bEar.png
cp /pictures/bear.png /pictures/alias/BEar.png
cp /pictures/bear.png /pictures/alias/beAR.png
cp /pictures/bear.png /pictures/alias/bEAR.png
cp /pictures/bear.png /pictures/alias/BEAr.png         <-- can be there are duplicate aliases
cp /pictures/bear.png /pictures/alias/BEAR.png
cp /pictures/bear.png /pictures/alias/BEAr.png         <-- can be there are duplicate aliases

Someone have idea what I can do about? I tought to use awk but till now i made only disasters.
# 2  
Old 03-31-2018
How can the number of aliases be determined? Why zero aliases for test.png?

Please show some of your "disasters" for discussion.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-31-2018
Quote:
Originally Posted by RudiC
How can the number of aliases be determined? Why zero aliases for test.png?

Please show some of your "disasters" for discussion.
The list is made from one service of television, the pictures are the symbols of the tv channels, so if one channel is popular can be have some alias with better or lower quality of resolution, but can be also some alias are removed if the cannel become less popular.
If the channel is not popular, can be there are not aliases, like channels repropose the show of the day before.
Sometime also happens event, like footbal match or maybe reality show, so can be there are new random channels temporary.
I have no way to know the exact number of aliases, everytime I recive the list can be totally different.
So I tried to do something using the tags <01> and <02> because anyway <01> is one channel and between <02> and <01> there are the aliases, but is not working :P

Code:
awk -vlines=$(cat /pictures/alias_list.txt | wc -l) -vsource="/pictures/" -vtarget="/pictures/alias/" '/<02>/{getline;while($0 !~ /<01>/){print "cp " source SOURCE OFS target $0;if(NR==lines){exit};getline}} /<01>/{getline;SOURCE=$0;next}' /pictures/alias_list.txt > /pictures/alias.txt

Telling the truth I tried to copy one example I found online but I made only disasters :P :P

Thinking now probably I need add with my and the tag <01> at the end of the list... Mmmmm..... I am so confuse.
# 4  
Old 03-31-2018
Not sure I understand, but does this help:
Code:
FN="randomname.png"
for i in {1..10}; do P=$(( RANDOM * (${#FN} - 4) / 32768 )); T=${FN:P:1} ; echo ${FN:0:P}${T^}${FN:P+1}; done
raNdomname.png
randomName.png
randOmname.png
ranDomname.png
ranDomname.png
randomnamE.png
raNdomname.png
randOmname.png
rAndomname.png
randomName.png

?
Use this randomly generated name for the copy operation.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-31-2018
Quote:
Originally Posted by RudiC
Not sure I understand, but does this help:
Code:
FN="randomname.png"
for i in {1..10}; do P=$(( RANDOM * (${#FN} - 4) / 32768 )); T=${FN:P:1} ; echo ${FN:0:P}${T^}${FN:P+1}; done
raNdomname.png
randomName.png
randOmname.png
ranDomname.png
ranDomname.png
randomnamE.png
raNdomname.png
randOmname.png
rAndomname.png
randomName.png

?
Use this randomly generated name for the copy operation.

Mmmmm... No I think am not clear to explain, I try again making one example better

I recive one list of pictures like this, this is one TXT file

<01>CBS.png<02>
cbs.png
CBS HD.png
CBS SD.png
CBS HD +1.png

<01>E!.png<02>
<01>Disney Channel.png<02>
DISNEY CHANNEL.png
DISNEY CHANNEL HD.png
<01>Fox.png<02>
FOX.png
FoX.png
FOX HD.png
FOX FHD.png
FOX FHD.png
Fox +1 HD.png
Fox +2 HD.png
.
.
The list Is long like 2000 channels, the channels are inside the tags <01><02>

I recive also una usb key with the pictures I wrote with the blue color

So I have the foldre /pictures/ with inside the files

CBS.png
E!.png
Disney Channel.png
Fox.png
.
.
.
plus other 2000 files.

I need create the files I wrote in orange color, so in my mind I want make one file .sh to execute and duplicate the files blue to the files orange. I want make one file like this

cp /pictures/
CBS.png /pictures/alias/cbs.png
cp /pictures/CBS.png /pictures/alias/CBS HD.png
cp /pictures/CBS.png /pictures/alias/CBS SD.png
cp /pictures/CBS.png /pictures/alias/CBS HD +1.png
cp /pictures/Disney Channel.png /pictures/alias/DISNEY CHANNEL.png
cp /pictures/Disney Channel.png /pictures/alias/DISNEY CHANNEL HD.png
cp /pictures/Fox.png /pictures/alias/FOX.png
cp /pictures/Fox.png /pictures/alias/FoX.png
cp /pictures/Fox.png /pictures/alias/FOX HD.png
cp /pictures/Fox.png /pictures/alias/FOX FHD.png
cp /pictures/Fox.png /pictures/alias/FOX FHD.png
cp /pictures/Fox.png /pictures/alias/Fox +1 HD.png
cp /pictures/Fox.png /pictures/alias/Fox +2 HD.png

So when I execute it will gnerate all alias pictures I need inside the folder /pictures/alias/

I tried to do it with the command

Code:
awk -vlines=$(cat /pictures/alias_list.txt | wc -l) -vsource="/pictures/" -vtarget="/pictures/alias/" '/<02>/{getline;while($0 !~ /<01>/){print "cp " source SOURCE OFS target $0;if(NR==lines){exit};getline}} /<01>/{getline;SOURCE=$0;next}' /pictures/alias_list.txt > /pictures/alias.sh

But is not working, I hope is more clear now Smilie

Excuseme if my english is not really well!

Last edited by Tapiocapioca; 03-31-2018 at 12:01 PM..
# 6  
Old 03-31-2018
OK, let's try our luck. How about
Code:
awk -vSRC="/pictures/" -vTGT="/pictures/alias/" -vDQ='"' 'gsub (/<0(1|2)>/, _) {ORG = $0; next} {print "cp " DQ SRC ORG DQ, DQ TGT $0 DQ}' file4
cp "/pictures/CBS.png" "/pictures/alias/cbs.png"
cp "/pictures/CBS.png" "/pictures/alias/CBS HD.png"
cp "/pictures/CBS.png" "/pictures/alias/CBS SD.png"
cp "/pictures/CBS.png" "/pictures/alias/CBS HD +1.png"
cp "/pictures/Disney Channel.png" "/pictures/alias/DISNEY CHANNEL.png"
cp "/pictures/Disney Channel.png" "/pictures/alias/DISNEY CHANNEL HD.png"
cp "/pictures/Fox.png" "/pictures/alias/FOX.png"
cp "/pictures/Fox.png" "/pictures/alias/FoX.png"
cp "/pictures/Fox.png" "/pictures/alias/FOX HD.png"
cp "/pictures/Fox.png" "/pictures/alias/FOX FHD.png"
cp "/pictures/Fox.png" "/pictures/alias/FOX FHD.png"
cp "/pictures/Fox.png" "/pictures/alias/Fox +1 HD.png"
cp "/pictures/Fox.png" "/pictures/alias/Fox +2 HD.png"

If happy with the result pipe it through sh to make it really happen...
This User Gave Thanks to RudiC For This Post:
# 7  
Old 03-31-2018
Is working perfectly! Many hours of my time are saved!! Thank you so much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scan directories and create a list of files

Gents, Please can you help. I want to create a list which contends the complete patch of the location of some directories with the size of each file. need to select only .txt file In this case I am try to find the subdirectories tp1 and tp2 and create the output list. jd175-1 tp1... (3 Replies)
Discussion started by: jiam912
3 Replies

2. Shell Programming and Scripting

Script or alias to backup all files opened by vi

we want to backup all opened files by vi before editing also with version information. i wrote below alias to backup crontab file content with version info. What i want know is to make this opened files by vi. We want to prevent user mistakes by adding this alias. alias crontab='DATE=$(date... (4 Replies)
Discussion started by: sebu
4 Replies

3. Shell Programming and Scripting

Create a list of missing files

Hello Guys I have a big list of files in one directory. And Some are missing . Example ls -l 2191off-r0.sps 2193off-r0.sps 2194off-r0.sps 2197off-r0.sps 2198off-r0.sps 2200off-r0.sps I would like to create a file with the list only missing files. Or if is possible to create in ... (4 Replies)
Discussion started by: jiam912
4 Replies

4. Shell Programming and Scripting

Create empty files from a list on file

Hello Guys. Please I would like to create empty files from a list In file1 will be the followin values, so i will like to create for each name a empty file. file1 2191off-r0.sps 2192off-r0.sps 2193off-r0.sps 2194off-r0.sps 2195off-r0.sps So I need to get 5 empty files. Thanks for... (7 Replies)
Discussion started by: jiam912
7 Replies

5. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

6. Shell Programming and Scripting

Create an alias

I want to create an alias cpage4 and create a postscript file For example I want to call cpage4 file.f which creates the file file.ps I have written like this but don't know how to continue alias cpage4 '/usr/bin/mpage -m40 -4AHP- \!* (6 Replies)
Discussion started by: kristinu
6 Replies

7. Shell Programming and Scripting

Create files from a list and then populate them

I have a list of filenames that I want created - they must be created via a certain naming convention due to the software I'm using. Once they are created I have another file that will be used to populate them with data. So far this is what I have: #For each line in text file "foo_txt" create... (2 Replies)
Discussion started by: MaindotC
2 Replies

8. Shell Programming and Scripting

How to create multiple list of files in a directory ?

Hi, i have say 100 files in a directory. file1.log file2.log file3.log file4.log file5.log file6.log ... ... ... file99.log file100.log ========= I need to create another file which contains the list of al these log files. each file should contain only 10 log file names. it shud... (4 Replies)
Discussion started by: robinbannis
4 Replies

9. Shell Programming and Scripting

Shell Script Create List of Deleted Files

Hi, I want to put all the deleted files in a txt file. Because i want to backup my image server which has thousands of jpg images. I wrote a shell script which will copies images from image server to backup image server. I setup a cronjob which runs on every five minutes. & through timestamp it... (8 Replies)
Discussion started by: mirfan
8 Replies

10. UNIX for Dummies Questions & Answers

Create a list of files that were modified after a given date.

Hello Mates! I'm kinda new to unix and need to a solve a problem. Input: date Situation: With the given date I need to find a list of all such files starting from a given path that were modified after the given date. I experimented with the "find" with "-newer" but did not quite get it... (4 Replies)
Discussion started by: rkka
4 Replies
Login or Register to Ask a Question