New answers tagged text-processing
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"
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]) &&...
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:
~$ ...
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;
...
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)...
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 ...
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 ...
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 ...
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 ...
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&...
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 $...
Top 50 recent answers are included
Related Tags
text-processing × 8524awk × 2982
sed × 2361
shell-script × 1125
grep × 852
bash × 725
linux × 578
shell × 383
csv × 373
regular-expression × 372
perl × 345
command-line × 333
scripting × 287
files × 222
bioinformatics × 187
columns × 182
text-formatting × 179
sort × 177
join × 135
cut × 110
json × 102
xml × 102
replace × 96
numeric-data × 89
text × 82