New answers tagged awk
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 '
...
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 --...
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)'
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"
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 ...
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 $...
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 ...
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:]]*([^[:...
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 | ...
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 ...
Top 50 recent answers are included
Related Tags
awk × 8885text-processing × 2982
sed × 2895
grep × 1112
bash × 1021
shell-script × 1007
linux × 881
shell × 489
perl × 461
csv × 381
regular-expression × 354
scripting × 284
command-line × 188
text-formatting × 178
cut × 151
files × 148
sort × 137
join × 134
bioinformatics × 129
columns × 127
find × 93
string × 89
numeric-data × 84
date × 83
python × 76