Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm working on a little script at the moment and have got myself stuck. Basically I want the script to take an argument (a filename) and then parse the argument and remove the file extension. So for example if I submit:
./myscript test.pov
It should return
"The filename is now test"
and should remove the file extension. It prints out the following error message:
tr: empty string2
I am assuming this is because I left '' unspecified in the tr part of it. I was thinking it should be able to just remove that part of the string... but obviously not. Can anyone help me on getting this simple script to run? Much appreciated
#!/bin/bash
#here is myscript
for filename in "$@"
do
echo "Examining file $filename"
$filename = `echo $filename | tr '.pov' ' '`
echo "filename is now $filename"
done
I think the problem here is an incorrect use of tr.
tr (used in this manner) only replaces the occurence of one character with another.
What it is trying to do in your script is replace each character in the first list with the corresponding character in the second list. But the second list is empty, hence the error message.
If the second list is shorter than the first list it will replace each succeeding character in the first list with the last character in the second list. (I think - man tr to be sure).
Whoops one more question while I'm at it. If I wanted to add something back to the variable how would I do that.. here's a better idea of what is going on...
for filename in "$@"
do
echo "Examining file $filename"
/opt/bin/local/povray $filename +W320 +H180
file=$(echo $filename | sed -e 's/\.pov$//')
echo "filename is now: $file"
curl -T $file.png -u userassword -O ftp://test.ca/public_html/xgrid/
echo "jobs done"
done
So basically what I want to do is render a file in povray, then strip the povray extension from the file, and then upload the finished result (a .png file) back to my server. I was thinking that sed could again be used but I just can't figure out the syntax... I'm a noob.
Thanks a lot guys. That was just the info I needed. I don't need to convert the files with image majick because when povray renders the files it automatically outputs to a .png file. It's good to know that you can do it that way though.
In that case, you just need to change from using the 'convert' command to the 'mv' command.
If the files are contained in different subdirectories, the 'find' command may be preferred to a 'for' loop, calling a script or bash function
find ./povrootdir -iname "*.pov" -exec pov2png "{}" \;
---
#!/bin/bash
# Change extension from .pov to .png
mv "$1" "${1%.pov}.png"
---
However, if you are producing a script for more than interactive use, you will want to include error correction, such as checking the extension, so you don't produce a 'file.POV.png' or 'file.jpg.png' if it is called incorrectly.
Well I'll let you get back to the fun of 3d animation. I'm into using Blender3d myself, however it's been a while.
I have a directory full of *.jpg.html files and I'm trying to use these methods to strip out the '.jpg' part, however I am having no luck. I might need some special characters in my command to do it properly or something.
What would be a better solution is if I could get the original command that created the files to strip out the .jpg part. Here is my situation. I have a directory full of JPG files that I need a corresponding page assigned the name of each. For example: P319004.jpg needs a page called P319004.html. The page that it creates must have a template inside of it. I've sucessfully done that with this command:
#ls *.jpg | awk '{print "cp 'template.html' "$1".html"}' | sh
template.html being the template that it copies into the new file it creates.
But that creates P319004.jpg.html. I want to strip out the '.jpg' part. Any help is extremely appreciated, as this will save me tens of hours doing it manually on a Windows box.
BTW, I still need to search the files and replace the references to the photos to the correct photos, but I'll figure that stuff out later.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.