-
JAA
Two hours later, and it has written out about one quarter of the bundle... :-|
-
Doranwen
aww
-
Doranwen
I've managed to write three shell scripts to automate the *rest* of my process
-
JAA
Nice!
-
Doranwen
though I still need to figure out how to reduce the resulting file size
-
Doranwen
the final file is a massive pdf, lol
-
Doranwen
starting from some pngs
-
Doranwen
(converting to jpgs before pdf shrinks the size nicely)
-
JAA
This repo bundle is killing my disk. :-|
-
JAA
git is reading ~100 MB/s and writing ~200 kB/s. Yeah, that'll take a while...
-
JAA
On an HDD, as well.
-
JAA
This sucks.
-
JAA
Can't even TSTP/STOP it either because it's stuck on disk I/O.
-
JAA
Well, good to know I guess.
-
» Doranwen frowns at puzzle she is stuck on
-
Doranwen
I've got a script to auto-crop a whole batch of pics
-
Doranwen
and that works fie
-
Doranwen
*fine
-
Doranwen
but I'm realizing the part I want to crop actually shifts position over the course of the set of pics
-
Doranwen
about 1 pixel every 5 pics
-
Doranwen
I'm quite happy with the shell script to crop, but I don't know how to set up in the shell script to set an iteration number to loop over for each pic it crops, and actually modify the crop parameters any time it lands on one divisible by 5
-
Doranwen
for the last one I ran (I edit it to change the parameters for each batch I'm cropping):
paste.ee/p/rLKtT
-
Doranwen
I'd basically be adjusting the 456 number upwards every 5 pics it crops
-
JAA
Bash can do basic arithmetic. It's called 'shell arithmetic' in the official documentation I think. You'd have to implement a counter yourself though.
-
Jake
^ Are you talking about numbers on the image file names or just counting?
-
Doranwen
well, there ARE numbers on the image file names, but the counting is all I mean
-
JAA
Oh right, if the files are numbered anyway, that would work.
-
Doranwen
the files are indeed numbered starting with 1
-
Doranwen
well, there's textbitoffilename-1.png
-
Doranwen
but same idea - the part before the numbers is absolutely identical and consistent
-
Doranwen
I don't think I know what to search for to find useful results for this
-
Doranwen
if I go the counter route, I can use that - I didn't know to call it a counter till you said that, that helped me find something
-
Doranwen
but if it's easier to use the file names…
-
thuban
Doranwen: `list=(*.png); len="${#list[@]}"; for (( i=0; i<$len; i++ )); do somethingwith $i; somethingwith ${list[$i]}; done`
-
» Doranwen studies command to try to understand it all
-
thuban
-
JAA
If they're numbered like that without padding zeros, note that the order won't be right.
-
Doranwen
oh, I can add padding zeros, I was doing that already with pyrenamer
-
Doranwen
but that can happen at any stage
-
Doranwen
so I didn't know if I should do that before or after the cropping
-
Doranwen
(well, any stage *before* the pdf one)
-
Doranwen
they start out without the zeros, I add them in
-
Doranwen
so I can do that before cropping
-
JAA
If you have padding zeros and you use the filenames for arithmetic, you need to be careful with the numeric base as numbers starting with a zero will be treated as octal by default. I got bitten by that recently when I was doing some nasty date calculation in Bash.
-
Doranwen
yeah, I saw something about that on a Stack Overflow post just a few min ago
-
thuban
(but the counter mechanism i describe above won't have this problem; you can safely use $i as a number)
-
Doranwen
JAA: "If that's an issue, you can do: if (( 10#$number % 5 == 0 )) to force $number to be interpreted as base 10 (instead of base 8/octal implied by the leading zero)."
-
JAA
Yep :-)
-
Doranwen
smart solution, lol
-
JAA
And yeah, the counter will not be padded.
-
Doranwen
anyway, I need to go read that arrays link to try to understand all of this
-
Doranwen
I only half-understand the command
-
thuban
basically, expand the glob '*.png' and load the results into an array (this is guaranteed to be lexicographic); get the length of the array; create an index variable i and loop from i = 0 to i = length, with access in the body of the loop to both i (the index) and array[i] (the value of the array at that index)
-
thuban
the man page i linked should cover all the relevant syntax
-
Doranwen
it's … a bit over my head, though I'm trying valiantly ;)
-
Doranwen
the one thing I definitely have a question about is, do I need to remove the non-numeric part of the filenames?
-
thuban
nope
-
Doranwen
didn't think so, from your explanation
-
Doranwen
it's taking the filenames as the list
-
Doranwen
and then counting how many it's got in the list
-
Doranwen
basically
-
thuban
exactly
-
Doranwen
?
-
Doranwen
excellent, I'm glad I'm following that
-
thuban
so as long as the full filenames sort in the order that you want, you're good
-
Doranwen
ok, so the next challenge is - how do I *change* the parameters on the crop every 5 pics, lol
-
Doranwen
because that's the whole idea here
-
Doranwen
the first five pics would be cropped with 1005x827+456+166, the next five with 1005x827+457+166, the next five with 1005x827+458+166, and so on
-
Doranwen
I had it all in `for f in *.png; do convert "$f" -crop 1005x827+456+166 +repage ../cropped/"$f"; done` which worked nicely but didn't adjust for the shifting center
-
thuban
set a margin variable, update it in the body of the loop (using $i), and then convert with `-crop 1005x827+"$margin"+166`
-
Doranwen
ooh, THAT's how I set it in there, ok
-
Doranwen
it'll take me a bit to figure that out, but I think I can do it
-
thuban
`margin=455` outside the loop, and then inside `if ! (($i % 5}}; then ((margin++)); fi`, if i recall my arithmetic syntax correctly...
-
Doranwen
why 455?
-
Doranwen
oh, because the first is 0
-
Doranwen
and 0 is divisible by 5?
-
Doranwen
so it automatically starts by adding 1
-
thuban
yeah
-
Doranwen
right now I'm stuck on the loops - am I not using the "for f in *.png" bit then, and if not, how am I telling it to grab each png in turn? there's some piece of this that's not clear
-
Doranwen
and I'll probably go "duh" when I see it
-
thuban
^ lol that's wrong, should be `(($i % 5))`. typo
-
Doranwen
but right now it's that general structure that's baffling me
-
Doranwen
(noted)
-
thuban
`list=(*.png)` expands the glob '*.png' and stores the results in the array 'list'
-
Doranwen
oh right, so I can call that somehow to pass it each filename?
-
Doranwen
well, my "it" was unclear
-
thuban
yes, `${list[$i]}` is the item at position $i in the list (so, the $ith filename)
-
thuban
you can pass it to `convert` just as you would `$f`
-
Doranwen
ah! ok
-
Doranwen
(sorry, I really did try to read that page, but I was understanding very little of it)
-
Doranwen
I *think* I have it, but I'm just reading over it all
-
Doranwen
the only part I'm trying to understand still, how it works, are the bits inside the for (( ))
-
Doranwen
setting the index to 0 to start, yes?
-
Doranwen
and saying run as long as it's less than the last file?
-
Doranwen
(though does that mean it won't run when it gets to the final file?)
-
Doranwen
the pages on for don't have any examples with multiple things inside there like that, so I'm not sure how they all work or why
-
Doranwen
the `for (( i=0; i<$len; i++ ))` bit
-
» Doranwen understands each of those separately but is having trouble understanding how it all fits in and functions in the overall process
-
JAA
That is a syntax you will find in many programming languages.
-
Doranwen
it does work, though - I tested by setting the actual convert line to echo first, just to see, and yup, it worked
-
JAA
It's `for (( start; condition; action ))`.
-
Doranwen
ah
-
JAA
`start` is executed at the beginning of the loop.
-
JAA
`action` is executed after every completion of the loop body.
-
Doranwen
aha!
-
Doranwen
thank you
-
Doranwen
these little things are the things I find that are the hardest to find info on, lol
-
JAA
And `condition` is the check that is run before the execution of the loop body to check whether it should still be looping.
-
Doranwen
but they make so many other things make sense
-
Doranwen
ahhh, ok
-
Doranwen
now I understand it all
-
JAA
So here, it starts with `i=0`, then increments the value after every iteration (`i++`), and keeps doing that until `i<$len` is no longer true, i.e. until i is equal to or greater than $len.
-
JAA
Which means it iterates over all indices of the array.
-
Doranwen
yep
-
Doranwen
yay, I understand it all
-
Doranwen
I knew if I kept hanging around you guys I'd start picking stuff up ;)
-
Doranwen
I appreciate the help greatly - I've got so much more of a framework now to hang more stuff on
-
JAA
Another useful thing when working with arrays is `for value in "${array[@]}"; do ... done`. That iterates over all values in the array (but doesn't get you the nice counter variable, so it's useless in this specific case).
-
» Doranwen nods
-
JAA
But there's also ${!array[@]}, which are the indices. In this case, `for i in ${!list[@]}` would be identical to the loop we discussed above.
-
Doranwen
JAA: is there an easy way to run a command on a range of files *within* that selection?
-
Doranwen
the only methods I'm seeing operate on all the files in the folder
-
Doranwen
but what if I wanted to, say, run a script on just files 177-185
-
Doranwen
all inclusive and every number in that range counting, but not on 1-176
-
Doranwen
I mean, I could just move out the other files, lol
-
Doranwen
and then move them back
-
Doranwen
but there's probably a way of specifying
-
Doranwen
I'm not seeing anything like that in the for loop pages I'm looking at
-
Doranwen
but I probably just don't know what to search for
-
Doranwen
oh wait, just set i to 176, lol
-
thuban
in this case you could do sth like `for (( i=177; i<186; i++ )) do somethingwith restoffilename-"$i".ext; done`
-
thuban
yeh
-
Doranwen
er, 177
-
Doranwen
yeah, it just occurred to me
-
Doranwen
no, 176 - it didn't apply it to 177 with that last attempt, only 178 onward, interesting
-
» Doranwen scratches head
-
Doranwen
yeah, that definitely was it
-
JAA
Ah yes, one of the two most common issues in computer science: naming things, caching, and off-by-one errors. :-)
-
Doranwen
lol
-
JAA
You said your files are numbered starting from one, but the array indices start from zero.
-
Doranwen
RIGHT, I forgot about that
-
Doranwen
I'd originally thought 176 and then figured 177 because thuban said it, lol - wasn't sure exactly why I'd thought 176, but now I guess I know
-
thuban
my suggestion just substituted i directly into the filename; i thought you were doing a new thing rather than still using the array access
-
Doranwen
ah
-
Doranwen
I just copied the code and modified it
-
Doranwen
from the last script
-
thuban
(btw, for more general-purpose selections you can use `vipe`--puts an interactive editor into a pipeline, so you can e.g. pipe `ls` into it, manually delete the stuff you don't want, and pipe the result out into other commands)
-
JAA
TIL. Does it default to vi though? Exiting that isn't straightforward. ;-)
-
thuban
i've never gotten that joke. if it were ed...
-
thuban
(EDITOR/VISUAL, so one presumes)
-
JAA
Lots of people struggle with vi. It takes a bit of time to get used to how it works.
-
JAA
And yeah, it uses /usr/bin/editor, EDITOR, and VISUAL with fallback to vi, at least on Debian.
-
thuban
i suppose on an old enough system it could instead be ed! "Note the consistent user interface and error reportage."
-
Doranwen
I've used vi some, but I always have to look up the commands before I do because I don't do it often enough to remember them, lol
-
JAA
I never bothered with vi. The only thing I know is: :q!
-
JAA
:-)
-
JAA
For manual edits, I generally use nano. For anything else, I use awk/sed/grep/whatever as appropriate.
-
JAA
Oh yeah, the chromium git bundling finished after almost 9 hours.
-
Doranwen
lol
-
Jake
9 hours? wow
-
rewby
The chromium repo is well known to be a... big one
-
masterX244
How fat was the result file?
-
programmerq
there are several ephemeral resources related to the buying and selling of cars. dealers might post a carfax for a given vin, but it'll disappear after it's sold, for example. There's limited public info for license plate->vin on sites like faxvin.com and vincheck.info but you need to search a specific plate to pull the info.
-
programmerq
it's mostly just boring stuff, but it might be a neat thing to try to archive. Thoughts?
-
JAA
masterX244: 22 GiB or something like that.
-
OrIdow6
programmerq: That's -bs material