Skip to main content

New answers tagged

0 votes

Extract one string between double quotations

What I would do with bash: IFS='"' read _ val _ < <(xprop -id "$(xdotool getactivewindow)" WM_CLASS) echo "$val"
Gilles Quénot's user avatar
0 votes

In consecutive rows: sum 2nd (value) column if IDs in 1st (key) column are identical

Using Raku (formerly known as Perl_6) If the order matters: ~$ raku -ne 'BEGIN my @a, my $i=0; for .split(/\s+/, 2) -> $k,$v { when $i == 0 { @a.push([$k, $v]) &&...
jubilatious1's user avatar
  • 3,903
2 votes

How can I find common prefixes in file names to group them?

Using Raku (formerly known as Perl_6) Raku regex below groups filenames by starting characters: minimum 3-or-more <alpha> characters followed by \h horizontal whitespace or _ underscore: ~$ ...
jubilatious1's user avatar
  • 3,903
0 votes

How can I find common prefixes in file names to group them?

In pure bash, a function with either pattern globbing like: myfind () { ( shopt -s nullglob; printf '%s\n' "$1"* ) } or RegEx matching like: myfind () { ( shopt -s nullglob; ...
Raffa's user avatar
  • 509
9 votes

How can I find common prefixes in file names to group them?

With perl: $ find . -print0 | perl -C -l -0ne ' if (m{/([^/]{4,}?\w)\b[^/]*\z}) { push @{$list{$1}}, $_; } END { while (($part, $list) = each(%list)) { if (($count = @$list) > 1)...
Stéphane Chazelas's user avatar
3 votes

How can I find common prefixes in file names to group them?

If you only accept the string to end at a word border then this gives you the potential common strings; tune that to your requirements: sed -n '/^\(\w\+ \w\+\) /s/^\(\w\+ \w\+\) .*$/\1/p' file Then ...
Hauke Laging's user avatar
  • 94.4k
0 votes

How can I delete from a file every second and fourth comma separated word using sed?

Using Raku (formerly known as Perl_6) ~$ raku -ne 'put join ",", .split(",")[0,2,4..*-1];' file Above is an answer written in Raku, a member of the Perl-family of programming ...
jubilatious1's user avatar
  • 3,903
1 vote

How to extract specific fields from systemctl output for a custom report

Using Raku (formerly known as Perl_6) ~$ raku -ne 'BEGIN my @a = <cron apache2 mariadb memcached php8.4-fpm redis>; \ .words[0..3].put if m/^ \h* [ @a \.service | mnt\- [ ncdata ...
jubilatious1's user avatar
  • 3,903
1 vote

Text processing - join every two lines with commas

One possibility is to use xargs and printf. This may be useful if you want to apply more complex formatting than separating with a single character as paste does: xargs -L 2 printf '%s,%s\n' -L 2 ...
Toby Speight's user avatar
  • 9,294
0 votes

Extracting "devname" from log message with re_extract

Using grep(1): $ cat in date=2025-03-26 time=12:45:57 devname="this-is-the-host" devid="CD188764823423" eventtime=1742993157871312130 tz="+0000" logid="0001000014&...
Jim L.'s user avatar
  • 8,785
0 votes

Extracting "devname" from log message with re_extract

Using double quote as awk field separator your target string would be the second field. dname=$(awk -F'"' 'BEGIN{OFS=FS}{$1="";$3=$1;print $1,$2,$3}' input_file.txt ) Check it: echo $...
canupseq's user avatar
  • 1,914

Top 50 recent answers are included