Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

1 vote
Accepted

Open specific URLs in certain app?

The closest you can get with xdg is using url-scheme-handlers, i.e. mailto, http, ftp... and so on. xdg-settings list default-url-scheme-handlers This will make Google Chrome the default handler for ...
JayCravens's user avatar
2 votes

How can I only execute sed commands after so many pattern matches in macOS?

With awk, count the number of times we match pattern and use getline to read the next line once we reach the count of two. After printing the line, we may quit. $ awk '/^pattern$/ && ++count ==...
Kusalananda's user avatar
  • 337k
2 votes

How can I only execute sed commands after so many pattern matches in macOS?

Try this command: $ sed -n '/pattern/{n;p;}' input.txt | sed -n 2p line 4 For fifth instance use 5p instead of 2p etc. Hardly any need for explanation.
dhm's user avatar
  • 1,628
3 votes

How to search in a pdf or text file by a regex pattern and output locations of matches?

I searched for "PDF grep" and the first hit was https://pdfgrep.org/ which looks like it might be exactly what you need. It is installable on Ubuntu with apt install pdfgrep And on Arch ...
terdon's user avatar
  • 243k
0 votes

change newline with space on certain condition with sed

Perl is a great tool for this sort of thing: $ perl -pe 's/\n/ / if /^#/' file #1713251479 sh lowbat.sh #1713251495 nvim lowbat.sh #1713252186 sh lowbat.sh The -p tells perl to print each input line ...
terdon's user avatar
  • 243k
2 votes

How to regex/escape backslash in Debian (Gnome) Text Editor?

You need to double the backslash: \\item (without the quotes). gnome-text-editor internally uses the GtkSourceView widget which is the one where the search and replace is implemented. You'll find that ...
Stephen Kitt's user avatar
3 votes
Accepted

change newline with space on certain condition with sed

In both your attempts, you read the whole file into the editing buffer and then replace all newlines with a space (the text will start with a #, so the substitution triggers in both cases and is ...
Kusalananda's user avatar
  • 337k
6 votes
Accepted

awk inside function causing errors

It is not the awk command causing issues, but the pattern you're using with grep. An unquoted parenthesis is special to the shell. It introduces a sub-shell, but in the context that you're using it, ...
Kusalananda's user avatar
  • 337k
0 votes

Grep that works with overlapping patterns

Using Raku (formerly known as Perl_6) ~$ raku -ne 'say "$_\t", ($/.elems given .match: :overlap, /aa/);' file #OR: ~$ raku -ne 'say "$_\t", .match(:overlap, /aa/).elems;' file ...
jubilatious1's user avatar
  • 3,335
0 votes

How to run grep with multiple AND patterns?

just directly MULTIPLY the patterns if you want them all to be true, thus eliminating any and all conditional branching awk '/regexp1/ * /regexp2/ * /regexp3/ … ' say if you need regex 4 FALSE while ...
RARE Kpop Manifesto's user avatar
1 vote

Grep that works with overlapping patterns

Using any awk: $ cat file x a aa aaa aaaa aa aaa aaaa $ awk '{printf "%s\t", $0; t=0; while(c=gsub(/aa/,"a")) t+=c; print t}' file x 0 a 0 aa 1 aaa 2 aaaa ...
Ed Morton's user avatar
  • 32.1k
4 votes

grep command regexp behaviour, is there a workaround?

If your grep supports it, you could use its perl regexp mode (generally with -P) and use a negative look-behind operator: $ echo "Hello. My name is James Bond, not Jean-Pierre nor Dr. Who! Nor ...
Stéphane Chazelas's user avatar
-3 votes

AWK: regex is not processed when passed as a variable

-You can does this way! df -h | awk '{ print $5" "$6"\t"$1}'|grep nvme0n1p4 where $5 is the field that shows the % of used space of the filesystem, and $6 is the field that shows ...
Joke Sr.  OK's user avatar
8 votes
Accepted

AWK: regex is not processed when passed as a variable

/$Regex/ is a regular expression that looks for Regex after the end of the subject ($) so can obviously never match. To use an awk variable as a regexp, you can't use the /.../ operator which doesn't ...
Stéphane Chazelas's user avatar
4 votes
Accepted

Regex pattern in sed to match hexadecimal address of fixed length

sed 's/0[xX][[:xdigit:]]\{16\}//g' Is standard syntax with basic regexps. Most sed implementations now support a -E option to switch to extended regexps¹: sed -E 's/0[xX][[:xdigit:]]{16}//g' [[:...
Stéphane Chazelas's user avatar

Top 50 recent answers are included