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 ...
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 ...
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 ...
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 ...
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
...
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 "$...
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 { \...
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)
...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
scripting × 4206bash × 1427
shell-script × 1061
shell × 682
linux × 616
text-processing × 274
awk × 270
sed × 176
files × 168
grep × 133
command-line × 130
ssh × 125
cron × 97
find × 85
variable × 74
python × 68
terminal × 67
ubuntu × 65
perl × 65
rename × 63
ksh × 59
debian × 54
networking × 53
centos × 49
regular-expression × 48