change file extension from root and subdirectories
Hello, my first post!
I'd appreciate help with this script, I'm new to this.
I have a media directory where I want to batch convert image file names from .img to .iso.
I've tried but get:
$ ./img2iso2.sh
./img2iso2.sh: line 13: syntax error: unexpected end of file
This is my unfinished script:
I assume this doesn't check subdirectories, even though I'd like it to. Maybe a combination of find, grep and sed should be used instead? These commands seems to work marvels in almost any situation.
Also, I'd think it would be smart to include some sort of check:
if there is a file called image.iso and one called image.img in the same (sub)directory; I'd like to change the name of that .img file to image-1.iso. But I don't even know where to start with this check!
If I understand the error message there's a problem with quoting? I've made so many trials that I can't remember where I started anymore.
Any help is greatly appreciated.
EDIT:
Searching the forum I found a better way to do the replacement of the file extension (here), but I wasn't so lucky with the subdirs.
But I am sorry to say that I could not get it to work.
The script runs and then I get prompt again but there is no indication if it goes wrong somewhere, I even tried to change the video root to a dummy directory to invoke some feedback but to no avail.
I've used "touch" to make some dummy files in the specified directory and subdirectories: some with the same name but different extension (.img and .iso, obviously, and some other just to see if they are affected), and some files with different permissions (chmod 777 on most).
But not one changed the extension.
The script itself is located in one directory level above the "media root" (as set in the script).
Unfortunately I really don't know anything about the Mac's world, so I can't help you anymore.
The obvious thing about the message "bad interpreter" is that it can't find the bash binary "/bin/bash" defined at the top of the script. If you issue "ls -l /bin/bash" what's the output?
About the "sh -x" thing, on Linux "sh" is a symbolic link to bash and it does work. On Mac I dont'know. To overcome this you can insert a line with the command "set -x" just before the video directory variable assignment. The effect is the same, but before you have to fix the interpreter problem or this is totally useless.
And about the "cat" command, it seems that your script file is a bit messed up.....
i do not have root on a solairs 10 server , however i do have the root role, i was wondering if I can change the root password as a a role with the passwd command? I have not tried yet.
and do i have to use the # chgkey -p afterwards?
i need to patch is why i am asking.
thanks (1 Reply)
Hi Guys,
i am trying to redirect a file wherein i need to change the extension of the file from .sh to .tmp, but getting an error
a=test.txt
sh test.txt > path/$(basename "$a" .sh).tmp
i need
test.tmp
---------- Post updated at 02:09 AM ---------- Previous update was at... (3 Replies)
Hi Team,
Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path.
I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this .
Here is the sample result... (6 Replies)
We are having a little problem on a server. We want that some users should be able to do e.g. sudo and become root, but with the restriction that the user can't change root password. That is, a guarantee that we still can login to that server and become root no matter of what the other users will... (2 Replies)
I need to write a script to :
list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
I have a directory that contains several files, out of which some files are have an extra extension for example
file1.new.new.new
file2.new.new.new
file3.new.new.new
file4.new.new.new
i want to write a shell script that rename all such file with only single extension like
file1.new... (7 Replies)
I searched the forum, but there was different type of rename.
Hello.
I have files in folder.
Like:
xxxxxxxx1.html
or
xxxxxxxx2.txt
or
xxxxxxxx3.tar.gz
and how to rename or change file extension case to
xxxxxxxx1.htm
or
xxxxxxx2.TXT
or (5 Replies)
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... (4 Replies)
Hi
I am writing a script which does an FTP of a set of files onto another machine and then would have to rename the files into a different extension on the source machine.
for example if the file being sent via FTP is sample.txt. Once the file has been transferred i would want to modify the... (2 Replies)
How do you write a shell script that change the extension of all the files?
e.g
chext rtf doc
where .rtf is the original extension
and .doc is the new extension
is it something to do with basename?
do I need a for loop?
Please help!
Unix SuperNewbie (4 Replies)