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.
the shell script is like I have to increment r if file DAT00000r-* exists and also if DAT0000(r+1) exits then also i need to incement r. likr suppose r=71 I have three files DAT000071-000232,DAT000072-339,DAT000073-792791.then I want to make r=74. also there may be possibility that i file DAT000071-1798.job DAT000071-818.cut also exist with other files mentioned above. in this case also i want my r=74.
if i use :
for i in `(find . -name DAT*$r-*)`
do
r=$((r+1))
done
then it incements r by 5 as .job and .cut files are also dere. I want to increment it only once in presence of DAT000r-798 DAT000r-798.job DAT000r-798.cut.
what shud i do??
please post the soln as soon as possible. i need it quite urgently..
i'll be very thankful
You are incrementing r for each file found by find. You need to test somehow for the highest value of r in your filenames. Are they all sequentially numbered? If so, you may be able to sort them, extract the r value from the last filename, and increment it just once.
Or, you can create a sorted list of filenames and extract the starting value of r from the last filename, and then increment r one time.
@penguiniator:
no the files are not in sequence.If DAT909.6989.job DAT911.6989.job DAT909.6989.cut DAT913.6989 are there, then i need r to become 910 instead of 909 and next time it shud becom 912..
In that case, what you can do is use a sorted list of filenames. Starting with the lowest numbered pair of names, subtract the r values from each file name. If the difference is greater than 1, add one to the r value of the lesser of the two r values to get the value to use.
If the names are in a list sorted lowest to highest, compare files 0 and 1. Then 1 and 2, and so on until you find a pair of files who's r value difference is greater than one.
If you don't find any, add one to the r value of the last file name in the list.
DAT000070-000000006 DAT000070-000000006.cut DAT000070-000000006.job files are exactly like this. here r=70.
DAT000075-000070709, DAT000073-000000006, DAT000070-000000006 DAT000070-000000006.cut DAT000070-000000006.job now i want to make r=71
then later
r=72
later r=74 as there is no file with r= 71 or 72 or 74
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.