News for hackers. Stuff that matters.
Re:Useful sed scripts and patterns by sitkack on Friday November 12, 2021 @02:19AM (#29197045)
If I measure time to solve a problem and not line count, using a language like Python or Ruby might be 2x the lines , for a line count approaching zero anyways, not sure that matters. Performance is comparable and I don't need to relearn anything and someone else who doesn't know awk/sed doesn't need to learn it.

And when one is using awk/sed that script is often invoked from a shell, bash for instance. And since the awk/sed can't hold its own as a general purpose programming language, now I am writing bash code, a personal sin.

Awk/sed made sense for the time and place they are from, but things have changed.

Re:Useful sed scripts and patterns by sergiosgc on Friday November 12, 2021 @05:37AM (#29197949)
> Awk/sed made sense for the time and place they are from, but things have changed.

Don't do that. Do not assume something is of no use because you don't know how to use it. Double that recommendation for tools that have widespread use. There is a reason they're used everywhere.

In the case of awk/sed/perl: Nothing beats them for composition in one-liner text processing pipelines.

Re:Useful sed scripts and patterns by pnutjam on Friday November 12, 2021 @10:46AM (#29200435)
plus, they exist in the vast majority of unix like systems. You don't have to install anything. They are just there and available to use. Even using them in a simplistic manner is light-years ahead of trying to do stuff manually.
Re:Useful sed scripts and patterns by sitkack on Tuesday November 16, 2021 @02:02AM (#29237724)
I have moved on to structured data, awk and sed handle line oriented text formats.

Don't assume I don't know how to use it. :)

One line verses ten, I'll take the more readable thing over the APL.

Re:Useful sed scripts and patterns by bear8642 on Friday November 12, 2021 @11:04AM (#29200694)
>Performance is comparable

Can't find links now, but fairly certain were stories in past about how switching to AWK from other tools increased performance

Re:Useful sed scripts and patterns by thaumaturgy on Friday November 12, 2021 @02:28AM (#29197090)
Yes, this is a Standard HN Reply: the "Specialist's Rebuttal". It's usually in some form of, "___ is obsolete, ___ is better in every way, everyone should just be using ___ now."

Okay, acknowledged. Python and Ruby are superior in every regard. Would you mind letting us chat about sed and awk now for a minute?

Re:Useful sed scripts and patterns by dang on Saturday November 13, 2021 @02:44PM (#29212601)
"Be kind. Don't be snarky."

"Please don't sneer, including at the rest of the community."

https://news.ycombinator.com/newsguidelines.html

Re:Useful sed scripts and patterns by yesenadam on Friday November 12, 2021 @02:46AM (#29197168)
I replied to someone's "There is no reason for anyone to program in C nowadays" recently on here with "But I like programming in C". They hadn't considered that reason in their mental survey of Every Possible Reason.

Also.. I use Awk every day, for all kinds of things. I forget the order of parameters in split, sub etc, which takes a few seconds to look up with man awk. I got into sed a while ago but never use it. Awk, together with sort and uniq sometimes, is all I need.

And it is interactive. You have an input. Print that out and look what needs to be done. Write the first transforming step in Awk. See what that did. Add the next step. See what that did. Extremely interactive. After a few minutes I have a one-liner (often 2 or 3 wrapped lines) that does exactly what I want, and easy to adapt to other similar things. I have very large bash history enabled so they stay Ctrl-R-accessible.

[dead]
Re:Useful sed scripts and patterns by dang on Saturday November 13, 2021 @02:46PM (#29212606)
Would you please not post in the flamewar style to HN, regardless of how provocative another comment was or you feel it was? This is not at all what we're trying for here.

https://news.ycombinator.com/newsguidelines.html

Re:Useful sed scripts and patterns by sitkack on Sunday November 14, 2021 @12:16AM (#29215494)
I don’t know what flame war style is, not playing dumb. I think the person behind the provocative comment isn’t much different than me.

I thought my comment might land ok, which due to a lack of response might have. It explained educated and <funny joke>

I might have typed the same thing in a different time.

*edit, it would be fun to have a forum board that allowed for out of band semantic information so … being cut off

Re:Useful sed scripts and patterns by dang on Sunday November 14, 2021 @03:36PM (#29220420)
Actually when I re-read your comment it doesn't seem so flamewarrish to me—sorry! a lot of the time I'm skimming these things in haste.

A couple bits that do correspond to 'the flamewar style', though, are when users start telling each other to "chill a bit"; and when people start arguing about "moving the goal posts and putting words in my mouth". It's a reliable sign of bad internet discussion when people start arguing about they are or aren't saying (rather than talking about whatever the ostensible subject was).

Re:Useful sed scripts and patterns by kerblang on Friday November 12, 2021 @01:08PM (#29202564)
Wait I need to toss an extra bomb over the wall and point out the superiority of swapping "sed" out for "perl -pe" and getting everything sed had plus superior regex without needing to learn much of anything new.

(I might be wrong about "everything" but that's what bomb-tossing is all about)

Re:Useful sed scripts and patterns by sitkack on Friday November 12, 2021 @02:38PM (#29203641)
Welcome to the discussion. I like it, I haven't perled in a while but does that mean you can evolve from a one liner to a full program using all of perl using this technique?
Re:Useful sed scripts and patterns by kerblang on Friday November 12, 2021 @08:21PM (#29206444)
I suppose it's a "pathway to perl" in the sense of a mild gateway drug. Perl is definitely one-liner-friendly. Every time I get into Perl I have to relearn it all over again (which is apparently not an isolated phenomenon), so I don't have great suggestions for digging further. I just habitually reach for perl -pe about 3/4 of the time.
Re:Useful sed scripts and patterns by baby on Friday November 12, 2021 @02:38AM (#29197139)
I really wish all these bash scripts would be replaced with python scripts.
Re:Useful sed scripts and patterns by stjohnswarts on Friday November 12, 2021 @04:01PM (#29204481)
Yeah I redid some scripts on my team for my own usage because our team bash guru maintained them and didn't want anyone to change them. So I did my own versions in python. Sure they were mostly 2x+ as long but they were very easy to read and modify and test. The bash guru finds out and brings it up at a team meeting trying to shame me, but it ended up with my boss asking the team, and they voted on using my scripts in lieu of the older bash scripts as I had written a few unit tests around them and the rest of the team understood them without digging out unix tomes.
Re:Useful sed scripts and patterns by sitkack on Friday November 12, 2021 @04:35PM (#29204808)
I have done something similar, what I really found worked well was to wrap the bash scripts in python to instrument them and if they just operate on data, you can even spawn another command and run them both at the time confirming that the output matches.

Great way to have confidence in a port and provide for a fallback path. Eventually the new code will take over the old code and the old code will wither and die.

Re:Useful sed scripts and patterns by stjohnswarts on Monday November 15, 2021 @06:30PM (#29234399)
It seems like when a bash script gets over say 50 lines or so I start doubting whether something should be a bash script :) . I saw an IRC client written entirely in bash once and it was quite a resource of esoteric bash scripting haha.