I have a long list of urls, and I'm trying to make a shell script to split each paragraph, separated by newline, into its own file. The files would need to be numbered
001 002 003 ...
and so on. Here's what I tried
#!/bin/zsh # Jakaa pitkä tiedoston kappaleet erilisiin tiedostoihin # Ei toimi. i=1 while read p; do if [[ "$p" == "k" ]]; then i=$((i + 1)) continue fi if (( $i < 10 )); then printf '%s\n' "$p" | tee -a kuvat_vol00"$i" elif (( $i > 9 )) && (( $i < 100 )); then printf '%s\n' "$p" | tee -a kuvat_vol0"$i" elif (( $i > 99 )); then printf '%s\n' "$p" | tee -a kuvat_vol"$i" fi done
I didn't know how to use the newline as delimiter, so that's why I use the letter 'k' instead. Stupid propably, I know...
The script works for a test file I made, something like:
123 k 123 k sdfsdf k k something
This gives me kuvat_001 and kuvat_002 with "123" and kuvat_003 with "sdfsdf" and so on. But when I try it with the urls, it just prints everything to a single file kuvat_001. I figured it has something to do with the slashes and other funny characters in the urls. How do I make it so that the shell doesn't interpret the special characters as special? Or should I use awk or script it in vim directly or something? I just don't know how to do either of those.
I'm a little bit ashamed to ask such a stupid question, but I've struggeled with this for like three days and I can't figure it out. I completely hands down suck at shell scripting, I know, but for some reason I'm excited to learn to use the computer properly. So yeah, I appreciate any help you can give me!
EDIT: The beginning of my input file looks like this. Can it be a problem with that?
https://2.bp.blogspot.com/l3Sk4TIKuKgEji-IJbxA7LetcDqWGbosjx-wSH8omLyNj4b1hq-Cs1wtFxd88XASw-FiJjjFSNbO=s1600 https://2.bp.blogspot.com/9GUUQ1HaC6m-4LbMKOZ7JLj55SqMfam9SHD6J48ezjGNY_hy8YUYYybhip_LKgYr9pKEI140Ewug=s1600 https://2.bp.blogspot.com/LYVJuq-I5kmAQUfLd_Kk28rJu1sOdo3md0ANHgS5w_wIVSIHSrwJAgO_MNm9DFg7GahrSYo4MFIp=s1600 https://2.bp.blogspot.com/qBITOIAnC09jmA-KDrFRyD3yGK_-2kNRyfr-AAJlitKTR8R7qzy8Q6v_1ukwZVBmIT8hBSRyinJE=s1600 https://2.bp.blogspot.com/9dwLT4h1pDRoOf0Mmp76zy04UGzPVEVTChNdTHAfqDPsb5fSSB2Tf4hFlFivNqPgplwKvdoEYNR0=s1600 https://2.bp.blogspot.com/D-9yBu7Zzg65mnfO2DuyU4aBcF9kAgllCJPpFuRKDrN5qUiuwJ9U-ReMhBg8b0Grg4PdcHlcmh2Y=s1600 https://2.bp.blogspot.com/RAUJka1fyc5yQAwh_O9bmqKj0vXgFvM9QvuIcKkItkxQiNFGgU1WUSBNqUQIGnnNpZaSzPHCyd8N=s1600