![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to match the last XML extension by using Case statement | sunitachoudhury | Shell Programming and Scripting | 3 | 04-06-2008 01:19 AM |
| change file extension from root and subdirectories | Astrid | Shell Programming and Scripting | 10 | 02-17-2008 07:18 AM |
| Help with multiple file rename - change case of part of file name | steve7 | UNIX for Dummies Questions & Answers | 7 | 06-30-2005 01:41 PM |
| how do i change extension | kswaraj | Shell Programming and Scripting | 2 | 06-28-2004 08:07 PM |
| How to change extension? | prkwan | Shell Programming and Scripting | 4 | 11-16-2002 07:14 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Create file and then change the extension case.
Interpreter should be bash.
1. The problem statement, all variables and given/known data: I need to make a file (myText.txt or song.mp3 or cloud.tar.gz or whatever) and then change the extension to (myText.TXT , song.MP3, cloud.TAR.GZ). It would be good if I can add all information in command line. Example Input: sh scriptName.sh <file name.extension> <file name.NEWEXTENSION> or vice versa . If the file already exists it should say something. 2. Relevant commands, code, scripts, algorithms: if [ ! -f $1 ] to check file exists 3. The attempts at a solution (include all code and scripts): Code:
CreateFile(){
if [ ! -f $1 ]
then
touch $1 > /dev/null 2>&1 && echo "File $1 created"
else
echo "Error: $1 file exists!"
fi
[/size][/font][/font] [font=Verdana][size=2]OLDEXT=${2/#.}
NEWEXT=${3/#.}
find "${1}" -iname "*.${OLDEXT}" |
while read F
do
NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
echo "mv \"${F}\" \"${NEWFILE}\""
mv -f "${F}" "${NEWFILE}"
done
4. School (University) and Course Number: TTU, 1 Last edited by DukeNuke2; 4 Weeks Ago at 12:42 PM.. |
|
||||
|
Hi Kdenmen,
What happens if you temporarily put extra echo statements after some of the variable assignments, especially those that contain pattern matching operators? Do you get the desired result? Also where does the function "Createfile" end and where does it get to be called? Why do you need the find command if you just need to rename a single file? S. |
|
||||
|
I still cant manage, because I am relatively new and never done any scripts.
Maybe someone will help me a bit. I found this, but I need to get the results I described in my first post. Thanks ahead. Code:
#!/bin/bash
usage () {
echo
echo "Usage: `basename $0` <search dir> <old ext> <new ext>"
echo
}
if [ -z "$3" ]; then
usage
exit 1
fi
OLDEXT=${2/#.}
NEWEXT=${3/#.}
find "${1}" -iname "*.${OLDEXT}" |
while read F
do
NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
echo "mv \"${F}\" \"${NEWFILE}\""
mv -f "${F}" "${NEWFILE}"
done
exit 0
|
|
||||
|
I have to bump my own thread.
Thanks ahead. I made a post to forum, but never got a anwer. Maybe you know someone who still can help me. Code:
#!/bin/bash
----------Dont know exactly but my code ---
touch > /tmp/newfilename
umask 077 && mkdir /tmp/tempdir.$$)
exit 2
----------------------------------------
usage () {
echo
echo "Usage: `basename $0` <search dir> <old ext> <new ext>"
echo
}
if [ -z "$3" ]; then
usage
exit 1
fi
OLDEXT=${2/#.}
NEWEXT=${3/#.}
find "${1}" -iname "*.${OLDEXT}" |
while read F
do
NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
echo "mv \"${F}\" \"${NEWFILE}\""
mv -f "${F}" "${NEWFILE}"
done
exit 0
Code:
sh myshellscriptname.sh temporaryfolder temporaryfile filecase1 filecase2 |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|