Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Baxate
Feb 1, 2011

gonadic io posted:

Speaking of terrible programmers, this is a pro click: https://github.com/CocoaPods/CocoaPods/issues/4989#issuecomment-193772935

I don't know what cocoa pods is, but I'm assuming it involves a plang. Please, somebody prove me wrong

real q: how is this different from homebrew and like the go language package manager. I guess they don't do shallow fetching but I'm pretty certain they use GitHub as a cdn

Adbot
ADBOT LOVES YOU

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
the github dude in that thread mentions that they had to work with the homebrew people on something similar

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
imo why blame these innocent programmers for Linus' mistake

VikingofRock
Aug 24, 2008




anthonypants posted:

ok thanks :shobon:

so i found this sed script on snack overload and it does exactly what i want, which is great, but i'm not sure how it works. basically it pulls the lines that begin with "zone" or "file" in the named.conf and returns the domain names. i only want to return the zone file, and i can edit it to do that, but here's what i want to know:
1) what is [^"]* supposed to mean
2) what does a comma mean
3) what in the hell does //!d mean, why are there two of them, why does removing one of them remove every other blank line, this is the most confusing part of this string to me
i think i might have to do a perl or a python later on but this sed nonsense is mystifying me right now and i cannot get over it

Okay so after spending a little too much time on this, I think I have it figured out. A sed expression of the form '/regexA/,/regexB/' matches everything from an occurrence of regexA to regexB. A null regex (//) is equivalent to the previous regex used. So an expression of the form '/regex/,//' matches everything the regex, and then everything up to and including the next occurrence of the regex. In this case, that matches this:
pre:
zone "example.com" IN {
        type master;
        file "db.example.com";
A ! after a regex will perform an action of everything that does not match that regex, instead of everything that does, and in this case the action is d (or delete). So '/regex/,//!d' will delete everything except for the stuff that falls between occurrences of this regex (inclusive), or in other words this will filter the output down to what was in that "pre" block. This is the end of the first sed command (terminated by the semicolon). The second sed command is then another //!d, which will delete everything which didn't match the first regex. This cuts the output down to this:
pre:
zone "example.com" IN {
        file "db.example.com";
Finally, there is one more command, which is the 's//\2/'. This replaces the each line matching the original regex (which is now every line) with the stuff in the second capture group, which is the "example.com" and the "db.example.com".

IMO this is a really weird and roundabout way of doing things, and if I was going to use sed for this I would probably write something like
code:
sed -n 's/^\s*\(zone\|file\) "\([^"]*\)".*/\2/p' named.conf
IMO this is a little more readable (by sed standards), and uses more well-known sed tricks.

PS this was a hugely helpful reference for me in figuring this out.

VikingofRock fucked around with this message at 22:58 on Mar 8, 2016

Soricidus
Oct 21, 2010
freedom-hating statist shill

VikingofRock posted:

Okay so after spending a little too much time on this, I think I have it figured out. A sed expression of the form '/regexA/,/regexB/' matches everything from an occurrence of regexA to regexB. A null regex (//) is equivalent to the previous regex used. So an expression of the form '/regex/,//' matches everything the regex, and then everything up to and including the next occurrence of the regex. In this case, that matches this:
pre:
zone "example.com" IN {
        type master;
        file "db.example.com";
A ! after a regex will perform an action of everything that does not match that regex, instead of everything that does, and in this case the action is d (or delete). So '/regex/,//!d' will delete everything except for the stuff that falls between occurrences of this regex (inclusive), or in other words this will filter the output down to what was in that "pre" block. This is the end of the first sed command (terminated by the semicolon). The second sed command is then another //!d, which will delete everything which didn't match the first regex. This cuts the output down to this:
pre:
zone "example.com" IN {
        file "db.example.com";
Finally, there is one more command, which is the 's//\2/'. This replaces the each line matching the original regex (which is now every line) with the stuff in the second capture group, which is the "example.com" and the "db.example.com".

IMO this is a really weird and roundabout way of doing things, and if I was going to use sed for this I would probably write something like
code:
sed -n 's/^\s*\(zone\|file\) "\([^"]*\)".*/\2/p' named.conf
IMO this is a little more readable (by sed standards), and uses more well-known sed tricks.

PS this was a hugely helpful reference for me in figuring this out.

here is the best sed advice you will ever read: don't loving use sed for anything, ever.

or awk

or bash (except as an interactive shell)

we have plangs now and they do everything the old unix utilities can do better. like seriously i once replaced a ~bespoke artisanal ksh script~ with like three lines of perl and it ran something like 1000x faster as well, because amazingly enough programming with a programming language is better than programming with a bunch of random dsls talking to each other over untyped character streams even when the programming language in question is goddamn perl

qntm
Jun 17, 2009
I weep for you if the bash script became a performance bottleneck

Arcsech
Aug 5, 2008

Soricidus posted:

here is the best sed advice you will ever read: don't loving use sed for anything, ever.

or awk

or bash (except as an interactive shell)

we have plangs now and they do everything the old unix utilities can do better. like seriously i once replaced a ~bespoke artisanal ksh script~ with like three lines of perl and it ran something like 1000x faster as well, because amazingly enough programming with a programming language is better than programming with a bunch of random dsls talking to each other over untyped character streams even when the programming language in question is goddamn perl

awk at least is v good for getting what you need out of huge log files.

for very nearly any other purpose it is bad though

JawnV6
Jul 4, 2004

So hot ...
who needs grep! just pipe everything to splunk, set up a custom event to trigger when the relevant

compuserved
Mar 20, 2006

Nap Ghost

Soricidus posted:

even when the programming language in question is goddamn perl

the last time i saw perl was when a coworker wrote this to identify distinct file extensions in a git repo:

pre:
find . -type d -name '.git' -prune -o -type f -printf '%f\0' | \
  perl -CSDA -Mutf8 -0 -l0 -n -e 'print /(\..+)/ ? $1 : $_ ;' | \
  sort -u -z | \
  perl -CSDA -Mutf8 -0 -l12 -n -e 's/\p{XPosixCntrl}/�/g ; print $_ ;'
i'm the U+FFFD REPLACEMENT CHARACTER

i'm also the assumptions regarding UTF-8

gonadic io
Feb 16, 2011

>>=
Weep away, I recently replaced a system that was 8k lines of bash and stored procs (that took 2-3 hours) with 600 lines of scala that takes about 10 seconds.

fritz
Jul 26, 2003

Soricidus posted:

here is the best sed advice you will ever read: don't loving use sed for anything, ever.

or awk

or bash (except as an interactive shell)

we have plangs now and they do everything the old unix utilities can do better. like seriously i once replaced a ~bespoke artisanal ksh script~ with like three lines of perl and it ran something like 1000x faster as well, because amazingly enough programming with a programming language is better than programming with a bunch of random dsls talking to each other over untyped character streams even when the programming language in question is goddamn perl

perl's shipped with complete sed-to-perl and awk-to-perl translators since i think the beginning

MrMoo
Sep 14, 2000

gonadic io posted:

Weep away, I recently replaced a system that was 8k lines of bash and stored procs (that took 2-3 hours) with 600 lines of scala that takes about 10 seconds.

Please don't say you just dumped the table and re-implemented the stored proc in Scala?

gonadic io
Feb 16, 2011

>>=

MrMoo posted:

Please don't say you just dumped the table and re-implemented the stored proc in Scala?

Stored procS

Nobody's really sure what it was doing but dozens of temporary tables were created I think.

It was parsing a bank's end of day files and inserting them into the db so I just threw away the entire thing away and reimplemented it in Scala with an orm

JewKiller 3000
Nov 28, 2006

by Lowtax

JawnV6 posted:

who needs grep! just pipe everything to splunk, set up a custom event to trigger when the relevant

this sounds like a request from offshore. "please trigger when the relevant"

JawnV6
Jul 4, 2004

So hot ...

JewKiller 3000 posted:

this sounds like a request from offshore. "please trigger when the relevant"
whenever i think the sarcastic point and/or joke is complete i just stop typing and hit po

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

gonadic io posted:

Stored procS

Nobody's really sure what it was doing but dozens of temporary tables were created I think.

It was parsing a bank's end of day files and inserting them into the db so I just threw away the entire thing away and reimplemented it in Scala with an orm

you don't seem to understand, we actually like stored procedures in here :hb:

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

gonadic io posted:

Speaking of terrible programmers, this is a pro click: https://github.com/CocoaPods/CocoaPods/issues/4989#issuecomment-193772935

I don't know what cocoa pods is, but I'm assuming it involves a plang. Please, somebody prove me wrong

:eyepop:

suffix
Jul 27, 2013

Wheeee!
speaking of sed,
about the most common thing i do with ad-hoc shell commands is stuff like "here is a list of urls, extract this query field to pipe through sort/uniq", or "here are a bunch of log lines, extract the numbers to run statistics"

i usually do something like
sed 's/^.*[&?]foo=\([^&]*\).*$/\1/'
is there a better tool for this?

jq is an amazing tool if you have a lot of data in json, btw

Notorious b.s.d.
Jan 25, 2003

by Reene

suffix posted:

speaking of sed,
about the most common thing i do with ad-hoc shell commands is stuff like "here is a list of urls, extract this query field to pipe through sort/uniq", or "here are a bunch of log lines, extract the numbers to run statistics"

i usually do something like
sed 's/^.*[&?]foo=\([^&]*\).*$/\1/'
is there a better tool for this?

jq is an amazing tool if you have a lot of data in json, btw

i do this kind of thing with perl/ruby/python. it's no harder than writing a shell pipeline, and it's easier to dump my command history into a real script when i need to.

for example, to get sed behavior out of perl:
code:
perl -nle  's/^.*[&?]foo=\([^&]*\).*$/\1/; print'

VikingofRock
Aug 24, 2008




IMO stuff like sed and awk and grep are great for one-off one-liners in an interactive shell, and are probably a useful skill to have if you spend a lot of time on the command line. If you need to write more than a line of bash though you should instead use a more modern scripting language.

Notorious b.s.d.
Jan 25, 2003

by Reene
why learn two lovely, single-purpose tools if you can learn to use a p-lang at the cli instead

fritz
Jul 26, 2003

Notorious b.s.d. posted:

why learn two lovely, single-purpose tools if you can learn to use a p-lang at the cli instead

correct.

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison
i got a 20k raise which makes me think I should have asked for more

JewKiller 3000
Nov 28, 2006

by Lowtax

uncurable mlady posted:

i got a 20k raise which makes me think I should have asked for more

:toot: gj man

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

uncurable mlady posted:

i got a 20k raise which makes me think I should have asked for more

lol nice 5 figgy raise fucktard

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
jk congrats

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
fucktard

JewKiller 3000
Nov 28, 2006

by Lowtax
oh come on mr president, what would you have to do to get an extra 20k from epic? threaten to move to somewhere hip, like milwaukee?

VikingofRock
Aug 24, 2008




Notorious b.s.d. posted:

why learn two lovely, single-purpose tools if you can learn to use a p-lang at the cli instead

Same reason you would learn any other tool--they are kind of nice for their (admittedly niche) domain. I'll admit that I don't know perl, but what you wrote in perl doesn't really seem any nicer than what I wrote in sed, and the equivalent python/ruby/whatever wouldn't be a one-liner so it'd be marginally more effort for something that doesn't need to be marginally more effort. I mean it's not like the basics of awk and sed are that complicated, so if you often find yourself in a situation where they would be nice, why not spend the half hour requried to learn them? (Admittedly I only learned them because my undergraduate advisor used them often in code that I needed to maintain, but they have occasionally been useful since then so I don't regret learning them).

MeruFM
Jul 27, 2010
is sed and awk just regex for i/o?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

MeruFM posted:

is sed and awk just regex for i/o?

I'm pretty sure sed is Turing complete.

e: have a Tetris https://github.com/uuner/sedtris

VikingofRock
Aug 24, 2008




MeruFM posted:

is sed and awk just regex for i/o?

Sed is a regex-based tool that is mostly used to transform text files from the command line, and to pull information out of them (like in the example that was linked upthread). It has almost identical syntax to substitution in vim, if you have ever used that. Awk is mostly used for dealing nicely with simple column-based data, again from the command line. The advantage of sed and awk is that they tend to allow very concise syntax for dealing with their respective use cases, which is nice for bash one-liners. Both can also be (mis)used as full-fledged programming languages in their own right, but as others have mentioned if you need these capabilities you should definitely be reaching for something a little more modern.

edit:

leper khan posted:

I'm pretty sure sed is Turing complete.

e: have a Tetris https://github.com/uuner/sedtris

This is awesome and horrifying.

MononcQc
May 29, 2007

This is my take on awk, with a 20 mins tutorial: http://ferd.ca/awk-in-20-minutes.html

JewKiller 3000
Nov 28, 2006

by Lowtax
sed stands for "stream editor" and is used for applying regex substitutions to files as in "sed -i 's/cloud/butt/g' article.txt"

awk stands for "aho weinberger kernighan" whose phd thesis involves the extraction of whitespace-separated data from files. the eponymous program is used like "cat piss | awk '{print $3}'". this is the only known use of the awk program.

MeruFM
Jul 27, 2010
i remember this now

my advisor had a hardon for awk and would write fairly large programs in it.

I think she tried to make me write one-liners instead of using notepad++ regex find-replace.

VikingofRock
Aug 24, 2008




MononcQc posted:

This is my take on awk, with a 20 mins tutorial: http://ferd.ca/awk-in-20-minutes.html

I've read this article before, but I'm gonna read it again because it is really good.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

MeruFM posted:

i remember this now

my advisor had a hardon for awk and would write fairly large programs in it.

I think she tried to make me write one-liners instead of using notepad++ regex find-replace.

:bufdo %s/dumbshit/dumbershit/ge

JewKiller 3000
Nov 28, 2006

by Lowtax
[dicks]

cowboy beepboop
Feb 24, 2001

MALE SHOEGAZE posted:

yeah it's real good

this reminds me that i reduced the size of one of our repos from 250mb to 2mb by filter branching a bunch of unused yaml files.

but id have to overwrite the reop to actually make a change i think and im afraid to

if you do this someone will complain in 6-12 months when their cowboy feature branch suddenly can't be pushed and they'll refuse to redo their work on the new repo.

Adbot
ADBOT LOVES YOU

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

VikingofRock posted:

Okay so after spending a little too much time on this, I think I have it figured out. A sed expression of the form '/regexA/,/regexB/' matches everything from an occurrence of regexA to regexB. A null regex (//) is equivalent to the previous regex used. So an expression of the form '/regex/,//' matches everything the regex, and then everything up to and including the next occurrence of the regex. In this case, that matches this:
pre:
zone "example.com" IN {
        type master;
        file "db.example.com";
A ! after a regex will perform an action of everything that does not match that regex, instead of everything that does, and in this case the action is d (or delete). So '/regex/,//!d' will delete everything except for the stuff that falls between occurrences of this regex (inclusive), or in other words this will filter the output down to what was in that "pre" block. This is the end of the first sed command (terminated by the semicolon). The second sed command is then another //!d, which will delete everything which didn't match the first regex. This cuts the output down to this:
pre:
zone "example.com" IN {
        file "db.example.com";
Finally, there is one more command, which is the 's//\2/'. This replaces the each line matching the original regex (which is now every line) with the stuff in the second capture group, which is the "example.com" and the "db.example.com".

IMO this is a really weird and roundabout way of doing things, and if I was going to use sed for this I would probably write something like
code:
sed -n 's/^\s*\(zone\|file\) "\([^"]*\)".*/\2/p' named.conf
IMO this is a little more readable (by sed standards), and uses more well-known sed tricks.

PS this was a hugely helpful reference for me in figuring this out.
this owns and is really helpful, thank you. i think i came across that sed faq too but didn't catch that commas are delimiters for an address range (wtf). your replacement is also way simpler for me to wrap my dumb head around. i don't need the zone/file capture group or whatever the filename is like that other guy, so i just made it look like this:
code:
sed -n 's/^zone "\(.*\)".*/\1/p'

  • Locked thread