| | |
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
![]() |
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
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!
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!
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Re: Processing file by file in a txt, and storing the name of the file being processed
0
#2 Sep 6th, 2006
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
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)
cd /to/my/directory find . -name '*.jpg' | \ while read file do mv $file "new"$file done
in directories that are close in terms of directory trees does not mean there are no intervening mountpoints. -
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Re: Processing file by file in a txt, and storing the name of the file being processed
0
#4 Sep 6th, 2006
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
Re: Processing file by file in a txt, and storing the name of the file being processed
1
#5 Sep 8th, 2006
![]() |
Similar Threads
- Pops Ups ect on laptop (Viruses, Spyware and other Nasties)
- First year assigment on reading file, sorting and outputting invoice (C++)
- Noob: needs help with file I/O (C)
- Help with multiple Windows 2000 partitions! (Windows NT / 2000 / XP)
- About blank error message keeps comming back (Viruses, Spyware and other Nasties)
Other Threads in the Shell Scripting Forum
- Previous Thread: Interacting with other Applications via dtksh
- Next Thread: Making a shell script executable from any directory
Views: 1745 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





