21 votes
Accepted

How can I shorten HH:MM:SS as much as possible?

As I understand you need to remove the leading zeroes, so let's suppose you have a file like this 00:00:30 00:01:30 00:30:00 01:30:00 30:00:00 would become 30 1:30 30:00 1:30:00 30:00:00 If that's ...
user avatar
3 votes

Using 2 For loop print the output of 2 answers from two different files

As @ilkkachu comments, paste is the best answer: paste a.txt b.txt or, with a single space as the delimiter in place of tab, paste -d ' ' a.txt b.txt For a shell-only answer, first don't read lines ...
user avatar
1 vote

File content from env var

A bash Process Substitution acts like a file: some-program-that-reads-a-file <(echo "$MY_ENV_VAR") #..............................^^..................^ Here's a demo of how a program ...
user avatar
1 vote
Accepted

Toggle screen resolution with a script, how?

Use process substitution: #! /bin/bash read resolution _rest < <(xrandr | grep '\*') if [[ $resolution = 1920x1080 ]] ; then xrandr -s 5 elif [[ $resolution = 1600x900 ]] ; then xrandr ...
user avatar
  • 42.8k
1 vote

Is there a way to run a hook (i.e. shell script etc.) when an audio device is opened or closed?

This is a shell script I came up with when trying to execute a code when something opens the microphone, you might be able to adapt it to your needs. The key is pactl subscribe: #!/bin/bash ...
user avatar
1 vote

Remove certain words and set word at end of string in files

You can use GNU grep to find files that contain at least one occurrence of the pattern and GNU sed to do the substitution in-place: ere='Get<[[:digit:]]+>\(([[:alnum:]_]+)\)' grep -rlEZe "$...
user avatar
1 vote

How to find first occurrence of string in log file, set T/F value as variable, and record changes that occur

Using Raku (formerly known as Perl_6) raku -e 'my @a = words; @a.splice(1, *-128); @a.splice(64,*-62); \ @a.=rotor(9); @a = @a>>.[1..*-1].flat.rotor(2); my @b; for 0..27 -> $i { \...
user avatar
  • 1,242
1 vote

How to find first occurrence of string in log file, set T/F value as variable, and record changes that occur

This may be what you want (untested since no testable sample input/output provided): awk ' { for ( i=2; i<=NF; i++ ) { if ( $i ~ /^[TF]$/ ) { tag = $(i-1) ...
user avatar
  • 22.6k
1 vote
Accepted

Parsing CSV with AWK, returning fields to bash var with line breaks

The multi line is a feature of a CSV cell, and you can use an utility that is CSV aware as Miller. As examples, if you have this CSV you can run mlr --csv cut -f fieldA acr.csv to cut the first ...
user avatar
  • 2,103

Only top scored, non community-wiki answers of a minimum length are eligible