everything wrong with free software

 "obedience breeds foolishness"

### cutb *originally posted:* jan 2022 the purpose of writing this was simple; i was trying to use the cut command in openbsd: ``` $ python -c "print '1234567890' * 80000" | cut -b 1-5 12345 ``` no problem there. yes, there was actually a reason for trying to trim a string to 80,000 character length, but this quick example only shows arbitrary python output. the version of cut in openbsd (i suspect the gnu version is not so limited, as that is a goal of the gnu project) can trim an 80,000 (here, 800,000) character line, but it cant trim it to longer than 2,048 characters: ``` $ python -c "print '1234567890' * 80000" | cut -b 1-3000 cut: [-bcf] list: 3000 too large (allowed 1-2048) Traceback (most recent call last): File "", line 1, in IOError: [Errno 32] Broken pipe ``` okay, in general im very happy with the openbsd versions of command line tools, but this wont do. cutb to the rescue: ``` $ python -c "print '1234567890' * 80000" | cutb 1-3000 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 $ python -c "print '1234567890' * 80000" | cutb 1-80000 | wc 1 1 80001 ``` here is the code: ``` #### license: creative commons cc0 1.0 (public domain) #### http://creativecommons.org/publicdomain/zero/1.0/ proginf = "cutb 0.1, jan 2022 mn" text arrstdin try sect command right 1 mid 1 1 # handle -num first sect left 1 ifequal first "-" newsect "1" plus sect sect newsect next # handle num ckdash instr sect "-" ifequal ckdash 0 newsect sect plus "-" plus sect sect newsect next # separate values startend split sect "-" startpos startend mid 1 1 int pos startend mid 2 1 ifequal pos "" endpos "" else endpos pos int next forin each text ifequal endpos "" endpos each len next linelen endpos minus startpos plus 1 now each mid startpos linelen print next except help "usage: cutb startpos- | cutb -endpos | cutb startpos-endpos | cutb pos" now help print next ``` the version of this i wrote at first took 10 or 15 minutes and saved me the trouble of recompiling cut. no telling how long finding and fixing the limit would take; ive edited and compiled a c program before, but im really not a c coder. adding startpos support and that sort of thing (which i didnt need yesterday, but i thought i should if im going to call it "cutb") to the already working code took about an hour. the next day, it occurred to me that i probably could have used awk for this. sure enough, the openbsd version of awk doesnt have the limitation cut -b has: ``` $ python -c "print '1234567890' * 80000" | cutb 1-80000 | wc 1 1 80001 $ python -c "print '1234567890' * 80000" | awk '{print substr($0,1,80000)}' | wc 1 1 80001 ``` so theres your unixy solution in openbsd. => https://wrongwithfreesw.neocities.org