sometimes people say that every time they need to use regex, they have to relearn how regex works. i actually don't have that issue, i have a fairly solid theoretical base for how the simple regex (the kind of stuff i might need to bust out on a whim) gets put together

the problem is that theory is different from practice and the time it takes me to figure out why something that Should work Doesn't is usually longer than just not using regex

i have a file where a bunch of lines have nothing but whitespace on them and i want to keep those lines there but just make them like \n\n, no spaces or tabs on the empty line

sed -i 's/^\s+$//g' input_file

this should work, right? like

"look for the beginning of a line, followed by one or more whitespace characters, followed by the end of a line. replace it with nothing. g flag means do it for every match, not just the first"

but it doesn't modify the file at all

and there aren't that many lines like that so if i just went in with a text editor and like

scrolled to a line that should be empty, yoinked it and hit enter, and just did that for each one

i'd be done by now

actually i just typed the same damn thing into the nano "replace by regex" feature and it just worked so

whatever

@monorail I think some regex implementations work linewise

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!