Code and comments

  • bizdelnick ( bizdelnick@lemmy.ml ) 
    link
    fedilink
    arrow-up
    6
    ·
    3 years ago

    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.

      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.

    • arglebargle ( westyvw@lemm.ee ) deleted by creator
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 years 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.

  • Papamousse ( Frederic@beehaw.org ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 years ago

    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…

    • 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.

    • bizdelnick ( bizdelnick@lemmy.ml ) 
      link
      fedilink
      arrow-up
      2
      ·
      3 years 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.