[SOLVED] Bash: How to increment an alphabetic value of a variable alphabetically?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Thanks for your efforts. Not really what I want. I have a bash script here:
Code:
#!/bin/bash
LEFT="http://www.xxx.xxx/languages-pronunciations/de/alphabetically/L/page-"
PAGE=1
URL="$LEFT$PAGE"
print $RIGHT
while wget $URL; do
((PAGE++))
URL="$LEFT$PAGE"
done
This involves getting a series of web pages containing lists of words. They are organised by page number which is why I have a loop to increment the PAGE variable to get a different page for each loop.
and so forth.
The pages are also organised by the initial letter of the word shown in bold above. So in the example above I would want to increment the "L" to "M" when all the words in "L" have been exhausted.
I hope that's clearer.
jdk
So what DO you want? Someone to write the script for you?
You asked how to go from letter to letter, you've been given that, any of those techniques could be used as an "outer loop" to go through letters with your inner loop doing the page stealing.
So what DO you want? Someone to write the script for you?
You asked how to go from letter to letter, you've been given that, any of those techniques could be used as an "outer loop" to go through letters with your inner loop doing the page stealing.
Obviously not. I wrote the entire script I have shown. Given the same question concerning numerical rather than alphabetic incrementing, the response would be, "Take a variable X and place it in the expression "((X++))" and its value will be incremented by one each time it's called. I hope that's clear enough for you concerning what I expect.
With a suitable replacement for LEFT, this should do what you want.
Code:
#!/bin/bash
LEFT="http://www.xxx.xxx/languages-pronunciations/de/alphabetically/"
for LETTER in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
PAGE=1
while wget "$LEFT$LETTER/page-$PAGE"; do
((PAGE++))
done
done
Now it does what you want...
Here is the same loop modified to only echo URL and fetch 3 pages for each letter to test it.
Code:
LEFT="http://www.xxx.xxx/languages-pronunciations/de/alphabetically/"
for LETTER in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
PAGE=1
while [[ PAGE -lt 4 ]]; do
URL="$LEFT$LETTER/page-$PAGE"
echo "$URL"
((PAGE++))
done
done
So with the information already in this thread and two lines added to your script to handle going from L to N, as I couldn't be bothered downloading more because 3 letters is enough to prove my letter incrementing works (and with a line to only download 10 pages max) I can download the following files:
Code:
-rwxr-xr-x 1 jdkaye jdkaye 376 Dec 18 21:16 dumbass.sh
-rw-r--r-- 1 jdkaye jdkaye 39714 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-1
-rw-r--r-- 1 jdkaye jdkaye 40534 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-10
-rw-r--r-- 1 jdkaye jdkaye 40213 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-2
-rw-r--r-- 1 jdkaye jdkaye 41005 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-3
-rw-r--r-- 1 jdkaye jdkaye 41097 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-4
-rw-r--r-- 1 jdkaye jdkaye 41041 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-5
-rw-r--r-- 1 jdkaye jdkaye 41027 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-6
-rw-r--r-- 1 jdkaye jdkaye 40427 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-7
-rw-r--r-- 1 jdkaye jdkaye 40963 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-8
-rw-r--r-- 1 jdkaye jdkaye 40396 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_L_page-9
-rw-r--r-- 1 jdkaye jdkaye 40134 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-1
-rw-r--r-- 1 jdkaye jdkaye 41424 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-10
-rw-r--r-- 1 jdkaye jdkaye 40285 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-2
-rw-r--r-- 1 jdkaye jdkaye 40515 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-3
-rw-r--r-- 1 jdkaye jdkaye 40851 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-4
-rw-r--r-- 1 jdkaye jdkaye 40983 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-5
-rw-r--r-- 1 jdkaye jdkaye 40913 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-6
-rw-r--r-- 1 jdkaye jdkaye 41041 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-7
-rw-r--r-- 1 jdkaye jdkaye 41107 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-8
-rw-r--r-- 1 jdkaye jdkaye 40440 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_M_page-9
-rw-r--r-- 1 jdkaye jdkaye 40337 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-1
-rw-r--r-- 1 jdkaye jdkaye 41055 Dec 18 21:17 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-10
-rw-r--r-- 1 jdkaye jdkaye 40466 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-2
-rw-r--r-- 1 jdkaye jdkaye 41088 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-3
-rw-r--r-- 1 jdkaye jdkaye 41548 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-4
-rw-r--r-- 1 jdkaye jdkaye 41450 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-5
-rw-r--r-- 1 jdkaye jdkaye 41212 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-6
-rw-r--r-- 1 jdkaye jdkaye 41118 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-7
-rw-r--r-- 1 jdkaye jdkaye 40908 Dec 18 21:16 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-8
-rw-r--r-- 1 jdkaye jdkaye 40969 Dec 18 21:17 ripped_from-f_r_o.com_languages-pronunciations_de_alphabetically_N_page-9
Quote:
Originally Posted by jdkaye
I hope that's clear enough for you concerning what I expect.
With a suitable replacement for LEFT, this should do what you want.
Code:
#!/bin/bash
LEFT="http://www.xxx.xxx/languages-pronunciations/de/alphabetically/"
for LETTER in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
PAGE=1
while wget "$LEFT$LETTER/page-$PAGE"; do
((PAGE++))
done
done
Thank you all very much.
(1) I wanted to use bash because beyond very simple bash scripts (I've written loads) I haven't done much bash writing.
(2) My real question was, "Does an alphabetic function exist in bash. I did not ask for nor did I expect anyone to write it for me in the event that such a function is not built into bash. I downloaded the bash manual (4.2) and did a thorough search of that manual before bothering members of this august group. I could find the numeric increment function (shown in an earlier post) and happily used it. I thought perhaps an alphabetic increment function did exist but I was too thick to find it in the manual so I asked here.
(3) I am fully aware that one can write a function doing that job but that is not what my question was and not what I expected. A simple "no, but you can write one yourself" would have sufficed.
(4) As for using Perl, one of the points of my task was teaching myself more about bash. If I wanted to do the same thing using another language I would have chosen Icon which is the language I'm most familiar with.
(5) Finally, I think I'll explore the unicode or ascii route. Now, I'll see if there's a bash function that converts octals/hexadecimals numbers to decimals and vice versa. But don't worry; I won't ask. I wouldn't want you to think I'm asking you to write my code for me.
Thank you all once again.
jdk
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.