Skip to main content

New answers tagged

0 votes

Include spaces and tabs in "awk" search and replace

Note that -i inplace, which is specific to the GNU implementation of awk and tries to emulate perl's -i option is unsafe to use that way. Here, you'd be better of using perl instead: perl -lpi -e ' ...
Stéphane Chazelas's user avatar
2 votes

Cleaning-up previous kernel RPMs after reboot

dnf config-manager setopt installonly_limit=2 Will set the limit of such packages, to take effect in the next transaction. Two is the minimum limit enforced here. Or, dnf remove $(dnf repoquery -q --...
John Mahowald's user avatar
2 votes

Cleaning-up previous kernel RPMs after reboot

Not 100% accurate but simple enough: rpm -qa | awk -F- -v r="$(uname -r)" '$1 == "kernel" && !index($0, r)'
Fravadona's user avatar
  • 1,601
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
1 vote

awk - print the leading part of a matching pattern with back references

Not actually back referencing nor it is with awk ... Rather with the well known and widely available grep ... Utilizing it's -P, --perl-regexp and -o, --only-matching options with a positive lookahead ...
Raffa's user avatar
  • 509
5 votes
Accepted

awk - print the leading part of a matching pattern with back references

Using gawk: $ awk '(patsplit($1,a,/-[[:alnum:]]{10}-[[:alnum:]]{5}$/,sep)) { print sep[0]}' <your-file This approach uses AWK: $ awk 'sub(/-[[:alnum:]]{10}-[[:alnum:]]{5}$/,"",$1){print $...
Prabhjot Singh's user avatar
1 vote

awk - print the leading part of a matching pattern with back references

I'd use perl for this rather than awk. The following perl one-liner is pretty brute force but it does the job. First it skips lines that don't contain a - (i.e. skips the header line), then it ...
cas's user avatar
  • 84k
4 votes

awk - print the leading part of a matching pattern with back references

If you want to use back-references, you could use perl instead, here in awk mode: perl -lane 'print $1 if $F[0] =~ /(.*)-[[:alnum:]]{10}-[[:alnum:]]{5}$/' Or even sed: sed -nE 's/^[[:blank:]]*([^[:...
Stéphane Chazelas's user avatar
9 votes

awk - print the leading part of a matching pattern with back references

No awk supports backreferences like print \1. GNU awk supports backreferences in various constructs but the BSD awk on MacOS does not. Try this using any POSIX awk (or BSD awk): $ kubectl get pods | ...
Ed Morton's user avatar
  • 35.8k
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

Top 50 recent answers are included