Wanted

Spread the love

Wanted: A bash utility that sends the contents of a file to standard output. It would be named spew. It would be like cat but with the problems oft’ complained about in cat fixed. There would be a few options. One option would be to chomp the final newline if there is one. Other options would change the character encoding. Another option would be to specify several commands to which the data could be sent simultaneously. But otherwise it would be pretty simple. Spew.

See the whole “WANTED” list here.

Have you read the breakthrough novel of the year? When you are done with that, try:

In Search of Sungudogo by Greg Laden, now in Kindle or Paperback
*Please note:
Links to books and other items on this page and elsewhere on Greg Ladens' blog may send you to Amazon, where I am a registered affiliate. As an Amazon Associate I earn from qualifying purchases, which helps to fund this site.

Spread the love

15 thoughts on “Wanted

  1. If cat has problems that are well documented, why not download the GNU cat source, figure out a way to incorporate a modal switch to make it do whatever it is you think is the right thing, test it and then submit it upstream?

  2. For chomping the last newline, I’d do something like

    awk ‘{n=$0;print o;o=n};END{gsub(“n”,””,n);printf(“%s”,n);}’

    This is as awkward as the requirement is IMHO rare, but at least it clearly shows what is going on. Alternatively:

    perl -e ‘$a=do{local $/; XXX;}; $a=~s/n$//;print $a’

    (where XXX stands for empty angle brackets which cannot be entered into a HTML-based blog comment).

    which makes use of the (probably not widely known) difference between ^, $ and a, z, Z in perl (and the effects of modifiers on that).

    What is bad about the following for the other purpose?

    cat file | command1 & cat file | command2 & cat file | command3

    (where cat might be avoided totally using simple redirection (which I again cannot enter here due to HTML misinterpretation), and the whole command line might be scripted.)

    I’m only moderately happy about adding rarely used strange features to a simple program that is supposed to do one thing well (IMHO already “cat -n” is too much).

    What are the other “oft complained” problems?

  3. @Greg (#4): I fail to understand why the URLs represent problems. AFAICT [1] is a beginner’s introduction to cat, [2] is the “useless use of cat award”, both with comments. What is really missing in cat and needed so desperately that cat should be enhanced (besides maybe embedding a lisp interpreter)?

  4. Isn’t there ‘dog’ for that? I’ve heard it’s better than cat, but I’ve never used it. ‘cat’ is as dumb as it gets, which is just what I want most of the time; when I want something different I don’t use ‘cat’ – it’s obviously not the right tool then.

  5. I’m with Ralf. What problems, specifically, are there with ‘cat’? It appears the only complaint is, “‘cat’ doesn’t do what I want it to do”.

    One of the maxims in *nix programming is “programs should do one thing only and do it well”. Now that was written back in the days of the (false, but often useful) *nix paradigm that all data could be treated as a stream of bytes – hence the shell constructs of pipes and I/O redirection.

    As a systems programmer, I never did buy into that particular paradigm, and for GUI programming the first maxim is pretty much dead, but they (the maxim and paradigm) still apply to shell programming.

    For example, some years ago I wrote a simple program that reads a text file (or stdin) and converts horizontal tabs to the appropriate number of spaces. This fits both the above maxim and paradigm.

    The transliteration of chars may be difficult or it may be easy, depending on your requirements. Last week I wrote a C function to convert any 8 bit ascii char to a printable, 7 bit, ascii char, with all diacritical chars mapped into their nearest English equivalent. Technically, it required 0 lines of code to do so. To write a program that did the same thing, reading stdin and copying to stdout, could be done in maybe 20 lines of C code.

    Redirecting output to the stdin of several programs simultaneously can easily be done by any language that supports the equivalent of popen 3.

  6. Ralf&LigtningRose, you have to read the comments on [1]. You’re sort of missing the point. My usees of cat are, in my opinion valid. I’ve been told to stop doing it. So, I want a new program called “spew” that does what I want cat to do, but isn’t cat, so the complainers can shut up.

    If, in the mean time, there is some real problem with cat for use as a text stream spitter, then fix them. If not, than maybe all we need is an alias.

  7. Sorry Greg, I read the comments at http://tinyurl.com/22smfv6 and I still don’t see any complaints about cat. Comment #3 by AnonymousCoward makes a valid comment on the misuse of cat, so I still don’t follow what you’re saying.

    cat does what it does, and I have yet to see any complaints about cat other than you’d like a few more features – possibly a valid criticism, but one unlikely to get much sympathy from the maintainers.

    If people are giving you flack for the way you use cat, perhaps you could post a couple of examples for review. Shell programming is not a trivial proposition.

  8. Greg, what the hell is wrong with you?

    In none of the links you’ve provided is there *any* evidence whatsoever for “problems oft’ complained about” with cat. Using a screwdriver for a hammer in no way implies there are problems with the design of the screwdriver.

    I know we’ve butted heads before but my offer of help was sincere.

    But if your nose is still so stuck in the air that you still believe you know 10 times as much about computers as I do, then why don’t you just STFU and write spew yourself. In BASIC.

    I started reading your blog for your social commentary which I find insightful, but your computer coding posts are, frankly and at best, banal.

  9. Lightning, I use cat like you would use a screwdriver as a hammer. And I like it.

    Why do you think that I think that I know ten times more about computers than you do? I was under the impression that you were an IT professional. I assume you know more than I do.

    However, there is a little problem: I have a computer sitting here on my desk, and for the most part I intend to us it s I wish. If there are things I could do better, I’d like to know about it, and if there are things that I can do that I don’t know about at all, I want to know about them as well.

    But if I chose to not be a purist in the of processes cycles and write what are essentially macros for personal use in a way that a system administrator would not do in order to get my own stuff done in a way that I find effective and enjoyable, then I simply don’t think I should be looked down on for doing that.

    From the point of view of a computer expert, it is very likely that my blog is not going to be that useful for you. It does not need to be. That is not what I am here for. Most/all of my Linux-related blogging is to entertain and encourage other people like me … supporting people with enough of an interest to mess around, but who are not experts, to get and stay involved with opensource and have some fun.

    And this is happening more and more. There are a lot of people like me out there We do not make the world go round . You do. IT experts make everything work and we are just playing.

    In my opinion as a command line dilettante, it is unfair to slap people like me when we are seen to play in a way that a professional.

    The Command Line is a nice SLR and a professional lens with which one can take great photos to edit on highly integrative hands on software on the computer. A PHS camera is for taking snapshots and having them printed at Target to pass around at holidays.

    But there are people who are not professional photographers who like to play with the SLR and fancier software and do fun stuff with their photo equipment. Those people should (and generally do) recognize that they are not professional photographers. So they should avoid doing things like trying to get jobs as professional photographers, etc.

    This is parallel. There are a lot fewer command line dilettantes out there than half-baked photographers. I”m one of them, and you keep telling me to stop what I’m doing.

    I certainly don’t mind critique and advice. I happen to think, however, that this:

    cat filename | command1 | command2 | command3 >> resultfile

    is fine, even better than

    command1 filename | command2 | command2 >> resultfile

    and I have not committed a crime against humanity by using the first rather than the second.

    And, the point of my post, tongue in cheek (to some extent) is to get a command that is just like cat (plus or minus) but that is called something other than concatenate so what when I use it to “spew” data I don’t get called on the carpet.

    LR, the name of the proposed command is spew. This is supposed to be at least a little funny. It is probably worth examining more closely why when a command line dilettante like me proposing to create ‘spew’ to replace ‘cat’ to avoid getting griped at gets griped at.

    Which is why I though you were being funny.

    You ended your comment with a quiver lipped fist-handed foot stomping trollish remark “I thought you were a GOOD blog but then you you … you turned out to be a BAD blog!!!” … but I know you are not a troll. I think there is just a misunderstanding of what my point is.

    My fault, I’m sure. I had actually written a post two or three days ago explaining more about my philosophy on this, and it is scheduled to go up in a couple of days. It may help further clarify (though this comment is now probably longer than that post!)

    G

  10. Greg, I don’t think that anyone is telling you that you can’t use cat. My understanding of the relevant posts, and certainly in my posts, I think the thrust was to get you to consider whether you actually need a cat. The key work in a UUOC is useless.

    As a photo hobbyist, if I saw someone trying to take pictures of the sun through their SLR I’d probably say that it’s a bad idea. The individual would be free to do what they’d like, but that doesn’t mean that it’s a good idea. If someone was blogging about photography and made a post about directly photographing the sun, I’m sure you’d have people jumping on it in a similar fashion. Not so that people don’t do the right way, but simply so they are at least taught the right way.

    Also, I could s/cat/religion/gi your post and the gripe would amount to the same thing. Many of these people are perfectly fine doing things they way they’re doing it. Should nonbelievers stop saying what we think because the (non-extremist at least) religious folks find their worldview totally functional?

    I understand the tongue-in-cheek nature of the post but when you’re posting material intended to teach, even informally, I think that subject matter experts have a duty and understandable desire to chime in.

    To reiterate a bit more succinctly: we’re not trying to be scripting snobs, we’re trying to help.

  11. I’m aware of both, though I thought my response was a better fit for this post rather than the one you linked to. Mainly because I don’t care what Greg does on his system. Hell, I think that the point about saving total cycles isn’t as obvious as that post makes it seem because using cat where it’s not needed can cause tokenizing problems that require more debugging. It’s situational. But again, I’m not addressing the matter of how one should code.

    My post here was to address the fact that no one intended to attack Greg, but merely to be informative.

    Otherwise, I’ve been reticent in tech posts here because I don’t care how Greg codes on his machine, and because he doesn’t care what I think about coding.

Leave a Reply

Your email address will not be published. Required fields are marked *