Problem scripting a copy and renaming shell executable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem scripting a copy and renaming shell executable
# 8  
Old 01-19-2015
Well, but the first:
Code:
cp `cat list.txt` new-folder/

--->
Code:
while read entry;do  
    cp $entry new-folder/
done<list.txt

Maybe this helps? (nevermind, its the same, got confused by those quotes which are supposed to execute, please use $( command ), it helps to read and helps to differ between commands and strings.

---------- Post updated at 09:35 ---------- Previous update was at 09:34 ----------

Quote:
Originally Posted by ilovedoritos
My code I tried worked partly, I got it to copy the specific Jpegs but it wouldn't copy ones again that existed in the folder, and I got it to sequentially rename the files but it renamed the source files and not the copied ones. I just don't know how to combine the functions
Yes, obviously...
As i already stated, there is no sense to copy 300 char a.jpgs....
# 9  
Old 01-19-2015
But I figure that if I can get the shell to rename the copied jpeg as it is pasted in the other folder then I won't run into the duplicate file name issue
# 10  
Old 01-19-2015
Doh, me not really wake yet, sorry.. i guess i figured it.


find . -name '*.jpeg' \
| awk 'BEGIN{ a=0 }{ printf "mv %s %04d.jpeg\n", $0, a++ }' \
| bash

If you run this in the original path, it will not rename the files in new-folder, unless new-folder is a child of the current path. (??)
If that is the case, i'm sorry i couldnt help and i'm out then.

Good luck.
# 11  
Old 01-19-2015
Quote:
Originally Posted by sea
Again, (just as far i understand you, which seems its not 'that' far), it makes now sense to copy the char-images, just make a one folder containing these, and call the specific image upon need.

Reuse what is already existing, there is no sense in having 300 letter a.jpg in several folders.

If that is not what you want to achieve, please elaborate more about that copy issue you mention, because from your first post, its quite (very) unclear to me what you actualy want to do OR what the precice issue is.
Specialy since you use a mv command rather that cp...

---------- Post updated at 09:32 ---------- Previous update was at 09:32 ----------

Neither do i in yours.
In mine its not required.
I think you understand. I have one folder that contains the Jpeg's (for this version of the experiment , this folder has 26 lowercase letters 10 numbers and a spacebar jpg) and the list.txt. I need the shell to copy the first jpeg listed in list.txt, and then paste it in the destination folder rename it to 0001.jpg, Wait for it to paste and then move on to the next line of list.txt and repeat
# 12  
Old 01-19-2015
One possibility is to rename on copy .

eg (warning untested code)
Code:
index="0000000"
for image in $(cat list.txt) ; do 
 cp ${SRC_DIR}/$image new_folder/${index}.jpg
 index = $(printf %06d $(( $index + 1 )) )
done

# 13  
Old 01-19-2015
Quote:
Originally Posted by sea
Doh, me not really wake yet, sorry.. i guess i figured it.


find . -name '*.jpeg' \
| awk 'BEGIN{ a=0 }{ printf "mv %s %04d.jpeg\n", $0, a++ }' \
| bash

If you run this in the original path, it will not rename the files in new-folder, unless new-folder is a child of the current path. (??)
If that is the case, i'm sorry i couldnt help and i'm out then.

Good luck.
Code:
find . -name

I know that period means it will rename the files in the current directory, but I need it to rename the ones it just copied in the new-folder
I don't know what I am doing, I just thought of this thing 3 days ago.

---------- Post updated at 03:21 AM ---------- Previous update was at 03:09 AM ----------

Quote:
Originally Posted by Skrynesaver
One possibility is to rename on copy .

eg (warning untested code)
Code:
index="0000000"
for image in $(cat list.txt) ; do 
 cp ${SRC_DIR}/$image new_folder/${index}.jpg
 index = $(printf %06d $(( $index + 1 )) )
done

I know nothing about how to code except what I've researched in the last 2 days.
# 14  
Old 01-19-2015
This does NOT apply if it is: ./new-folder

Try:
Code:
find /path/to/new-folder -name '*.jpeg' \
| awk 'BEGIN{ a=0 }{ printf "mv %s %04d.jpeg\n", $0, a++ }' \
| bash

hth
(note: my awk 'knowledge' is limited, but it looks right'ish, not sure about the last pipe to | bash though)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting problem

Hello. I hava homework for university but i cant do it and i need a little help if someone can help me :) I have to do a linux shell script. Write a script that does the following: 1. Check if there is a directory in / home with myDir name. If not, it creates it. 2. In the directory it... (1 Reply)
Discussion started by: alex4o0o
1 Replies

2. Emergency UNIX and Linux Support

Need support for a shell scripting problem

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. Shell Programming and Scripting

ksh shell scripting to copy a file

Hi. I am a new Unix admin and I've been tasked to write a ksh script that copies my .profile into my /home directory on all servers. I'm new to this and having a difficult time scripting it. Any ideas? (6 Replies)
Discussion started by: david_tech
6 Replies

4. Shell Programming and Scripting

Shell Scripting: Copy Files with Today's date

I was wondering the best way about finding files that were created today and copy them to a directory (grep ?). There can be multiple files for todays date or none. I am looking to copy all of the .lis files for todays date. I may need to modify the filename to include todays date but for the... (4 Replies)
Discussion started by: smkremer
4 Replies

5. Homework & Coursework Questions

Shell Scripting Problem...

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! Hello all,,, I am trying to finish my assignment for my CNET class. I am running into 2 problems... First the "Delete a file" (Option 1) When I run this option everything... (5 Replies)
Discussion started by: ozman911
5 Replies

6. Shell Programming and Scripting

Problem in loops in shell scripting

Hi, #!/bin/ksh $v="" for ((i = 1 ; i <= 5 ; i++ )) do v="THerrFile_$i.err"; grep -i "$i:Error" $v >>oraerror_output.txt done My requirement is to dynamically create variable like THerrFile_1.err,THerrFile_2.err etc. where my grep needs... (5 Replies)
Discussion started by: sudhir_83k
5 Replies

7. Shell Programming and Scripting

Shell Scripting problem

Hi guys, I am a newbie to shell scripting.Please help me to accomplish this task. Its very urgent,I should create a script which will do the following: i) "cd ~joseph/ ; mkdir -p Bing/Bong ;mkdir -p Bing/Bang" and then create 15 ".txt" files with content "Bing Bang Bong" in "Bong"... (1 Reply)
Discussion started by: mahesh_raghu
1 Replies

8. Shell Programming and Scripting

Shell scripting and ls -1 problem

Hey, I'm running knoppix and I'm trying to run a shell script to change multiple lines of text in multiple files #!/bin/sh for i in 'ls-1 test' do sed 's/bob/manny/'g $i > $i.0 mv $i.0 $i done Obviously this isn't the original file, but it's on another non-networked machine. What... (7 Replies)
Discussion started by: afroCluster
7 Replies

9. Shell Programming and Scripting

shell scripting problem

her i am trying to edit a database file which is actually a small file holding my friend's name and birthdays My Database DEEPAK 27/08 DEEPIKA 18/02 DHYAN 23/03 DIPANKAR 24/10 SNIGDHO 19/05 AYANNAR 17/12 BHAI 22/09 DEBAN 16/08 JAGADISH 02/06 SUBHOJIT 23/02 TOJO 17/09 SUDHIR 12/09... (1 Reply)
Discussion started by: mobydick
1 Replies

10. Programming

Renaming an executable file

HI How to rename an executable file in unix (3 Replies)
Discussion started by: bankpro
3 Replies
Login or Register to Ask a Question