bartificer / programming-by-stealth

Resources for the Programming By Stealth blog/podcast series at https://bartb.ie/pbs.
MIT License
23 stars 17 forks source link

Suggestion: Not a typo, just a different way to do it #19

Closed stephenwb closed 3 years ago

stephenwb commented 3 years ago

I added a small section showing how to cut the last N lines off a file using head -n -N filename where N is the number of lines to remove.

Since you talked in the actual show about the method you put in the notes, it doesn't seem to make sense to replace it completely, but you said something like "there isn't a command to cut the last line off of a file" but I think this is it.

Also, I forgot this commit also had a change of echos to echoes, so I lied, there is one typo.

bbusschots commented 3 years ago

I’m 90% sure this does not work on the Mac which is why I went with the uglier alternative that I did. I’m on my iPad ATM so I can’t check, but I don’t want to merge it without checking.

stephenwb commented 3 years ago

Aha, that makes perfect sense. I wrote and tested that against a CentOS 7 box, I didn't have my Mac available during the day to test, I just ASSumed that head would be standard.

stephenwb commented 3 years ago

Follow up: You are correct, of course. The MacOS version of head does not understand -n -1

However, I still think that a short mention that there is, in fact, a Linux command that does this task would be valuable (even if it doesn't work in MacOS because the head there is still from the good-old-days of BSD -- the man page footer says

BSD                              June 6, 1993                              BSD

)!

bbusschots commented 3 years ago

Follow up: You are correct, of course. The MacOS version of head does not understand -n -1

However, I still think that a short mention that there is, in fact, a Linux command that does this task would be valuable (even if it doesn't work in MacOS because the head there is still from the good-old-days of BSD -- the man page footer says

BSD                              June 6, 1993                              BSD

)!

Agreed — what's needed is a tweak to add the fact that it's Linux-only (or that it doesn't work on the Mac), then I'll happily merge.

stephenwb commented 3 years ago

@bbusschots Does this work for you?