ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
been playing with sorting files. file names are in format :
texttext_0001.bmp
texttext_0002.bmp
texttext_0003.bmp
texttext_0004.bmp
etc. into the thousands
have gotten as far as being able to isolate the numerical part of the filenames from the
extension and text preceeding the underscore. problem comes when i try to perform
math on the remaining numerical part i get errors because bash looks at this as octal
information. i knew how to use basic once upon a time to grab just the right part of the
string but can't figure this out for bash. how do i get bash to look at numbers with
leading 0's not as octal so i can work with them? either that or how do i strip out the
leading 0's?
for what it's worth, i'm making a loop that divides the numbers by 5 and sending the
files which are evenly divisible this way to another directory.
tia, and the script follows,
BabaG
#!/bin/bash
cd /home/babag/Buddies/Part-1
for i in *.bmp ; do
j=`echo "$i" | awk -F"." '{print$1}'`
k=`echo "$j" | awk -F"_" '{print$2}'`
if [ $((k % 5)) == 0 ]; then
mv $i /home/babag/Buddies/holding/$i
fi
thanks for the help everyone. wound up using the printf version from osvaldo.
the 10# solution from CroMagnon shows the 10# characters when echoed to
the screen. both work and i've got both in the script so i can study. thanks
again. and ogmoid, i apreciate the tip but as i'm learning i wanted to use the
others as i thought i'd learn more from them in the long run. thanks again to
all.
Yes, the 10# will echo to the screen if you print the variable, it only affects bash's treatment of the number for calculations. Since the only place you use $k is in the mod 5 calculation, I didn't think that would be an issue. Anyway, it's useful to know how to force bash to use a specific base - you can use up to base 64 if necessary.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.