orsetto

joined 2 years ago
[–] orsetto@lemmy.dbzer0.com 13 points 3 days ago (8 children)

I understand what argument could be made against musl, which is licensed under MIT, but what's wrong with GPLv2?

I remember Torvald saying something about not wanting to change the kernel's license to GPLv3, but I've never understood the differences

[–] orsetto@lemmy.dbzer0.com 3 points 1 week ago (2 children)

Are you opposed to using awk?

Not at all, I'm just not familiar with it so I find it confusing.

Although, looking at your command, i think I understand what it means

[–] orsetto@lemmy.dbzer0.com 2 points 1 week ago (1 children)

I see. I guess what confused me was that i didn't understand what addresses were.

Thank you for your explanations :)

[–] orsetto@lemmy.dbzer0.com 2 points 1 week ago (3 children)

I meant to ask what is the difference between, i.e., sed '/myregex/ s/from/to/ p' and sed '/myregex/ s/from/to/ ; p', but while testing to explain what i meant I answered myself, and in the process I also understood what addresses are ehe

Right, awk is a proper programming language, right? that'll be for another day...

[–] orsetto@lemmy.dbzer0.com 1 points 1 week ago* (last edited 1 week ago) (1 children)

!/dev/dm-2!!p

This weired me out until I read the explanation. I'm so used to the slashes lol

In the end I've used the first command you wrote, because KISS, but I appreciate your explanation

Check the sed man page for more details

Yes that's been my only source so far, but to be honest it's really cryptic. it might just be that I'm used to syscalls man pages (also sed is kinda complex it can't be easy to write a single man page for it)

[–] orsetto@lemmy.dbzer0.com 2 points 1 week ago (5 children)

The -n suppresses auto-printing

That's something I was missing! It makes the command look definitely less complicated.

Also, what is the difference between separating expressions with a space vs with a semicolon?

Easier IMHO is awk

Eh, that's another beast. For some reason tho I find sed more appealing.

22
Help with sed commands (lemmy.dbzer0.com)
submitted 1 week ago* (last edited 1 week ago) by orsetto@lemmy.dbzer0.com to c/linux@lemmy.ml
 

Hi all! I have always only used sed with s///, becouse I've never been able to figure out how to properly make use of its full capabilities. Right now, I'm trying to filter the output of df -h --output=avail,source to only get the available space from /dev/dm-2 (let's ignore that I just realized df accepts a device as parameter, which clearly solves my problem).

This is the command I'm using, which works:

df -h --output=avail,source \
    | grep /dev/dm-2 \
    | sed -E 's/^[[:blank:]]*([0-9]+(G|M|K)).*$/\1/

However, it makes use of grep, and I'd like to get rid of it. So I've tried with a combiantion of t, T, //d and some other stuff, but onestly the output I get makes no sense to me, and I can't figure out what I should do instead.

In short, my question is: given the following output

$ df -h --output=avail,source 
Avail Filesystem
  87G /dev/dm-2
 1.6G tmpfs
  61K efivarfs
  10M dev
...

How do I only get 87G using only sed as a filter?

EDIT:

Nevermind, I've figured it out...

$ df -h --output=avail,source \
    | sed -E 's/^[[:blank:]]*([0-9]+(G|M|K))[[:blank:]]+(\/dev\/dm-2).*$/\1/; t; /.*/d'
85G