/ssg/ - Shell Scripting General: Sed & Awk edition

Shell scripting general. Post your shell scripts and give feedback on other anons'. Discuss command line utilities and useful programs. Shitpost about bash vs. zsh vs. ksh vs. fish. Share your dotfiles. Have fun.

>Resources for learning / improving
tldp.org/LDP/abs/html/ - Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting.
shellcheck.net/ - Shell script analysis tool. Catches syntax errors and bad code. Available from the command line.
explainshell.com/ - Paste a shell command and it will explain the commands and arguments.
Reading the manpages is actually often quite helpful.

>Collections of Utilities
gnu.org/software/coreutils/coreutils.html - GNU Coreutils: The basic collection of Unix utilities.
joeyh.name/code/moreutils/ - Moreutils: A collection of "missing" utilities from coreutils.
suckless.org/ - Suckless: Minimal and composable programs and utilities.

>Videos to get you in the mood
youtu.be/8E8sUNHdzG8 - Luke Smith: Layin' down Pipes like a Unix Chad
youtu.be/w_37upFE-qw - Luke Smith: Unix Chad JUST WON'T STOP Piping!
youtu.be/QaGhpqRll_k - Luke Smith: Using `sed` and Regular Expressions

>Topics of conversation
Good composable programs that you've found.
Tips and tricks you've recently discovered.
Scripts you've written to improve your workflow.

Attached: sed-and-awk.jpg (1280x720, 125K)

Other urls found in this thread:

mywiki.wooledge.org/BashFAQ
github.com/boyEstrogen/Anime-Girls-Holding-Programming-Books
twitter.com/SFWRedditVideos

mywiki.wooledge.org/BashFAQ is a good source too.

You know, not everything needs a general. Better than 90% of the rest of this crap board anyway.

use jq

This resource is a lot better than TLDP. IMHO TLDP is actually a shit resource.

cd ..
dir
cd ../..
dir
cd ..

this but compile from source, stable versions are slow as fuck

Luke is a brainlet when it comes to shell scripting

GNU Coreutils aren't Unix utilities. They have been written from scratch for the GNU system. It's not only wrong to call these things Unix utilities, it also gets you into legal trouble or fun (depending on the POV): Years ago, the Linux kernel team actually got lawsuits for stealing proprietary Unix code in its system and utilities.
Judt call them GNU utilities.

Agreed. He's riding the POSIX train.

Stop trying to force another general. If you want to make a fucking thread about this, just make a thread about this. Or even just post in /dpt/.
It's pretty pathetic that you spent time preparing this bloated OP that nobody is going to read.

Attached: 1558278169227.jpg (785x1000, 396K)

There are two separate generals for in ear monitors and headphones and scripting is forced?

a=(C4 D4 G3 D4 E4 G4 F4 E4 C4 C4 D4 G3 G3 A3 A4 B4 C5 C5 D5 B4 A4 G4 A4 A4 B4 C5 A4 G4 G5 G5 D5 G4 A4 C5 A4 E5 E5 D5 G4 A4 B4 G4 D5 D5 C5 B4 A4 G4 A4 C5 A4 C5 D5 B4 A4 G4 E4 D5 C5 G4 A4 C5 A4 E5 E5 D5 G4 A4 B4 G4 G5 B4 C5 G4 A4 C5 A4 C5 D5 B4 A4 G4 E4 D5 C5);b=(.75 .75 .5 .75 .75 .125 .125 .125 .125 .75 .75 .5 .75 1.5 .25 .25 .25 .25 .25 .25 .25 2 .25 .25 .25 .25 .5 .25 .5 .25 1.75 .125 .125 .125 .125 .375 .375 .75 .125 .125 .125 .125 .375 .375 .25 .25 .25 .125 .125 .125 .125 .5 .25 .25 .25 .5 .25 .5 1 .125 .125 .125 .125 .375 .375 .75 .125 .125 .125 .125 .5 .25 .25 .25 .25 .125 .125 .125 .125 .5 .25 .25 .25 .5 .25 .5 1);for i in {0..84};do play -q -n synth ${b[i]} sine ${a[i]};done

Yes. Jow Forums has too many fucking generals, and many of them are way too specific.
Unless a general is about a wide topic that will always have potential new discussion (e.g. /dpt/) or is otherwise containing a lot of otherwise annoying/useless threads in one place (e.g. /sqt/), it's a fucking useless general. Anything ultra-specific or otherwise devolves into a circlejerking chatroom is a bad general.

Jow Forums is broken already user. Just lets have fun.

i like this general, way better than another apple thread

ill post in here, its the best general on this board

I like this thread.

me too

Good thread.

>luke smith

GTFO

PowerShell makes it unnecessary. You can just pass complex objects from 1 script to another.

>powershell
no

Anyone using mksh? I have it installed but I need a resource to compare features. Stupid simple stuff like the prompt and history.

#! /bin/bash

sleep 2 &&
scrot -s -q 100 "$HOME/.scrots/temp.png";
if [ ! -z $1 ]; then
convert -liquid-rescale 200% "$HOME/.scrots/temp.png" "$HOME/.scrots/temp.png";
fi
xclip -i -selection clipboard -t image/png < "$HOME/.scrots/temp.png";

script I wrote that copies a region from scrot into the clip board. its basically equivalent to snip tool, or sceen print & paint. could be more inspired

Generals are a fucking stupid idea brought by redditards and other scum. Jow Forums is not a forum.

doesnt work faggot

whats a cd ../..

Mandatory.
Screenshots with imagemagick
import -window root png:$HOME/x_$(date "+%Y-%m-%d-%H:%M:%S").png

Record desktop and stop recording if you bind it to the same key
killall -INT avconv 2>/dev/null || avconv -f x11grab -r 10 -s $(xrandr | grep '*' | tr -s ' ' | cut -d ' ' -f2) -i :0.0 $HOME/x_$(date "+%Y-%m-%d-%H:%M:%S").mp4 &

I bind both to the print screen and shit using xbindkeys.

Sorry, forgot to say the desktop recording is using avconv. Just change it to ffmpeg, is the same shit.

without generals Jow Forums would be way worse than it already it is
please dont swear

Trying to make a simple script to get the resolution and pass it to mplayer and watch videos on the framebuffer.
exiftool -ImageSize "$1" | tr -s ' ' | cut -d ' ' -f4 | tr x '\n' | sort -n | tail -n1
Not sure if it works as good as I think, I need the highest resolution that exiftool can give.

Yes.

Be thankful the other guy asked politely not to swear or I would be all over mocking you.

Microshitters btfo

i like shell script and anime

works great. you probably need to make the ~/.scrots folder, or rename it to whatever you want. dont be a retard on the internet

why
[ ! -z $1 ]
instead of
[ -n $1 ]
?

you are shit resource, TLDP is leet af

Is there a way to copy a .jpg image using xclip? I want to use ranger as my file manager exclusively, but the script I wrote only works with png
#!/usr/bin/env ruby
filename = ARGV[0] || abort('[!] Please specify an image.')
format = File.extname(filename).tr('.', '').to_sym[/png/] || 'jpeg'

system "xclip -selection clipboard -t image/#{format} -i #{filename}"

No.

#!/bin/sh
./python3 myscript.py

Attached: 34D004DF-8D02-4A4B-B913-D5B9667A1EA5.jpg (1920x1080, 194K)

retard

Pythonisas everyone

no reason, its just what I know

sasuga itoddler

Redpill me on sed. I have literally never once found an excuse to learn it, I almost always use awk instead. Is it just a matter of preference, or "the right tool for the job" where being familiar with one but not the other makes it right for almost all jobs, or are there really tasks where awk is strictly inferior to sed?

Sed is simpler for 1 off text manipulation tasks. It’s very readable and easy to test outputs before writing inline (if that’s what you’re trying to achieve). You should be able to do everything that sed does in awk, but with MUCH more control

It's full of bad practices senpai.

Friendly reminder to write portable shebangs.
#!/bin/sh for POSIX shell
#!/usr/bin/env bash for Bash, and similarly for other non-standard interpreters.

...

What are the best resources for pure shell scripting, just sh?

Friendly reminder that writing portable scripts is for cuckolds. Be proud of your system and don't bother about shit systems. If people want to run your script, they have to switch to a superior system.

Attached: 1547057964484.jpg (966x1200, 109K)

macfags btfo

Based && Redpilled

True, all scripts should be written for rc shell on plan9.

Attached: smug sip.jpg (1600x900, 90K)

based

It only works with png.

MacOS has dropped bash anyway due to GPL panic, zsh is the new standard shell.

`bash: Based: command not found`

Who makes these pics of waifus with tech books?

I just want to say thanks.

Attached: AAAAAAAAAAAAAAAAAAAAAAAAAAAH.jpg (1024x719, 66K)

I made this one specifically for this thread. And you're welcome, user.

github.com/boyEstrogen/Anime-Girls-Holding-Programming-Books

Well done.

Thanks user. Appreciate ya.

Attached: thumbs-up.gif (500x279, 876K)

Tagged gallery selector I made using dmenu. The info files are generated automatically by my download scripts.
#!/bin/sh
HDIR="$HOME/bin/data"

get_info () {
while read line ; do
if [ "$HDIR" = "$line" ]; then
continue
fi
FOLDER="$(echo "$line" | rev | cut -d '/' -f1 | rev)"
INFOFILE="$line/info.tsv"
if [ -f "$INFOFILE" ]; then
ARTIST="$(cat "$INFOFILE" | grep "^Artist" | cut -f2)"
NAME="$(cat "$INFOFILE" | grep "^Name" | cut -f2)"
TAGS="$(cat "$INFOFILE" | grep "^Tag" | cut -f2 | paste -sd ',' -)"
echo "$FOLDER - $NAME [$ARTIST] [$TAGS]"
continue
fi
echo "$FOLDER"
done
}

find "$HDIR" -type d | get_info | dmenu -i -l 20 | cut -d ' ' -f1 | xargs -I {} sxiv "$HDIR/{}"

Totally useless yes. The only thing I can think of to make a regular thread about a specific topic is to make a weekly or monthly or something like that. I can imagine there would be an okay amount of discussion for slightly more niche topics if there only was a thread at a certain time interval. I can imagine an Emacs weekly being nice for example.

dl imagemagick and add a line to convert from png to jpg or vice versa.