this post was submitted on 17 Nov 2023
36 points (100.0% liked)

Linux

1257 readers
46 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Code and comments

top 12 comments
sorted by: hot top controversial new old
[–] bizdelnick@lemmy.ml 6 points 11 months ago (1 children)

My 5 cents:

  1. When piping output of find to xargs, always use -print0 option of find and -0 option of xargs. This allows processing files with any allowed characters in names (spaces, new lines etc.). (However I prefer -exec.)

  2. There's an i command to insert a line in sed, it is better to use it instead of s/^/...\n/. It makes code more readable (if we can talk about readability of sed code, huh).

  3. If you want to split a delimiter separated line and print some field, you need cut. Keep awk for more complicated tasks.

[–] meteokr@community.adiquaints.moe 3 points 11 months ago (1 children)
  1. If you want to split a delimiter separated line and print some field, you need cut. Keep awk for more complicated tasks.

Depends on the delimiter too! For anyone else reading this, sed accepts many kinds of delimiters. sed "s@thing@thing2@g" file.txt is valid. I use this sometimes when parsing/replacing text with lots of slashes (like directory lists) so I can avoid escaping a ton of stuff.

[–] bizdelnick@lemmy.ml 1 points 11 months ago (1 children)

I know, but it is not the case I was talking about. I meant widely used commands like awk '{print $2}' that can be replaced with cut -f2.

[–] meteokr@community.adiquaints.moe 3 points 11 months ago

I know you know, as you already demonstrated your higher understanding. I just wanted to add a little bonus trick for anyone reading that doesn't know, and is learning from your examples.

[–] aarroyoc@lemuria.es 5 points 11 months ago

I always found "find" very confusing. Currently, I'm using "fd", which I think has a more sensible UX

[–] t_378@lemmy.one 3 points 11 months ago (1 children)

What software did you use to put the slide deck together? It seems to work so nicely when placed on a webpage, too...

[–] westyvw@lemm.ee 2 points 11 months ago

I don't know what OP used, but it could be any one of the Markdown presentation tools.

I like reveal.js

Your presentation can go in git, looks good anywhere, and easily shared. It's just html rendered.

[–] it_a_me@literature.cafe 2 points 11 months ago (1 children)

I've gotten tired of weird regex stuff in awk, sed, and grep, so I've moved to perl -E for all but the most basic of things.

[–] bizdelnick@lemmy.ml 2 points 11 months ago

In most cases extended POSIX regexes are enough and looks the same as perl regexes.

I also used perl until I needed to write highly portable scripts that can be run on systems without perl interpreter (e.g. some minimal linux containers). Simple things are also simple to do with grep/sed/awk, more complex things can be done with awk but require a longer code in comparison with perl.

[–] Frederic 2 points 11 months ago (2 children)

Using un*x since the 90s, this is all I know. I like awk but it can go fucking complicated, I once maintain a 5000 lines script that was parsing csv to generate JavaScript...

[–] palordrolap@kbin.social 2 points 11 months ago

At that point I'd be looking for languages that have libraries that do what I need. Both Python and Perl have online repositories full of pre-written things. Some that can read CSV and others that can spit out JSON. It's then a matter of bolting things together, which, hopefully, is a few lines of code rather than 5000.

There are even awk repositories, but I'm not sure there's a central, official one like PyPI or CPAN.

[–] JoeKlemmer@lemmy.myserv.one 1 points 11 months ago

Someone used the wrong tool for the job. If an awk script gets more than a few dozen lines, it's time to use another language/tool to process that data.