Processing file by file in a txt, and storing the name of the file being processed

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 3
Reputation: Alphabeta is an unknown quantity at this point 
Solved Threads: 0
Alphabeta Alphabeta is offline Offline
Newbie Poster

Processing file by file in a txt, and storing the name of the file being processed

 
0
  #1
Sep 5th, 2006
Hi!,
I'm kinda new to shell scripting, Here's a problem that I have faced and dunno how to solve:
First,
I want my script to rename the files stored in a .txt file line by line(there's no pattern that I can use with mv, so I want mv to deal with a file generated by ls /home/whatever/ > whatever_files.txt). So, Let's that that now mv is dealing with the first line in whatever_files.txt which has a file name /home/whatever/whatever545.jpg, I want the new file to be called file_whatever.jpg. But in order to do that, I figured out that I must store the name of the file in a variable and having a mv command which looks like this:
mv whateverhey.jpg file_$filename

but I dunno how to store that name in a variable and how to make mv deal with files listed in a text file.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: Alphabeta is an unknown quantity at this point 
Solved Threads: 0
Alphabeta Alphabeta is offline Offline
Newbie Poster

Re: Processing file by file in a txt, and storing the name of the file being processed

 
0
  #2
Sep 6th, 2006
I figured out that I can a non C-style loop to work with all the files in directory but when I write this it doesn't work:
for filename in *
do
mv $filename hello_$filename
done

????

Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: Processing file by file in a txt, and storing the name of the file being processed

 
0
  #3
Sep 6th, 2006
Shell Scripting Syntax (Toggle Plain Text)
  1. cd /to/my/directory
  2. find . -name '*.jpg' | \
  3. while read file
  4. do
  5. mv $file "new"$file
  6. done
PS: mv works only within a filesystem. Even though you may be
in directories that are close in terms of directory trees does not mean there are no intervening mountpoints. -
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: Alphabeta is an unknown quantity at this point 
Solved Threads: 0
Alphabeta Alphabeta is offline Offline
Newbie Poster

Re: Processing file by file in a txt, and storing the name of the file being processed

 
0
  #4
Sep 6th, 2006
I indeed sometimes try to access some directories behind mount points(for example, hdb1 mounted on /home/user/myfolder), while the script is being executed from the user home directory, Do you mean that this can result in some problems?

Thanks!
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 178
Reputation: jim mcnamara is on a distinguished road 
Solved Threads: 10
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: Processing file by file in a txt, and storing the name of the file being processed

 
1
  #5
Sep 8th, 2006
In that case you have to use cp. mv does not mv over mount points.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1745 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC