(no title)
jssfr | 7 years ago
> echoz.sh also uses cut, base64, stdbuf, tr, mkfifo, tee and sort.
tee can be eliminated if needed be, the others should probably be added to the list of dependencies, thanks.
> echoz.sh does not seem to have any "bashisms" so perhaps one does not actually need bash and other sh will suffice.
Indeed, there is a PR which I have to review which fixes that.
> The uses of cut to isolate substrings and tr to replace characters can also be acomplished using sed.
I would be interested how you would do especially the tr part in sed, given that sed, even unbufferedly, operates on "lines". I use tr to replace '>' (XML delimiter) with a line ending recognized by sed to be able to operate on individual XML elements.
The uses of cut could be replaced by sed in the script indeed, although it can’t be moved into the main sed script. I made an issue for that: https://github.com/horazont/xmpp-echo-bot/issues/6
<spoiler>
> "All you have is openssl, bash, dig, stdbuf and sed?"
I hope it is clear that this entire thing is ironic and the long list of dependencies -- especially given that bash could reasonably be used to replace sed here -- is supposed to underline that. I’ll gladly add more :).
</spoiler>
textmode|7 years ago
There is more than one tr part. :) I tried to be careful to refer only to where the task is replacing characters.
As for joining lines, I have used the same tr -d '\12' technique quite often in the past if the input is not contained in a file. For files I would sometimes use ed scripts.
IME, sed is one of the most ubiquitous programs in UNIX-like OS. I use it daily. However when sed cannot do the job or cannot do it fast enough, I use flex to write relatively small, single-purpose programs quickly. There is a good chance they will compile cleanly on a variety of OS. Perhaps flex is as available to the user as tr, mkfifo, openssl, etc., i.e., when the user has access to all those programs she also probably has access to flex, cpp, as, ld and cc.
I would be happy to provide an example directed at the xmpp-echo-bot solution if you can provide some sample input and the desired output, ICPC-style.
textmode|7 years ago
As an example, below is a one-off/reusable HTML/XML reformatter in flex. This makes HTML/XML easier for me to read. It also makes it very easy to process with sed and other line-based utilities.