3 votes
Accepted

Sed - How to replace two strings, but preserving what is in between them?

This kind of thing is much easier with perl whose regexps have non-greedy repetition operators: perl -i -pe 's{\[\((.*?)>(.*?)\)\]}{<ref name="$1">$2</ref>}g' your-file Note ...
Stéphane Chazelas's user avatar
2 votes
Accepted

Whats the meaning of this sed command sed '/^[[:space:]]*$/d'

Matches any line that only contains space characters between the beginning (^) and the end ($) of a line. https://regex101.com/ is your friend. /…/d instructs sed to delete any match, so this just ...
Marcus Müller's user avatar
2 votes

AWK match exact value from comma separated column in brackets

Using any awk: $ awk '$(NF-2) ~ /[[,]22[],]/{print $1}' file 33.xx 24.1b 1.52 With some more comprehensive sample input that includes more than just the sunny day cases where we find a match where we ...
Ed Morton's user avatar
  • 30.2k
2 votes
Accepted

How to output regex matches as many-to-one combinations?

You can do something like: perl -l -0777ne ' while (/\@EventHandler\(([^)]+)\)\s+class\s+(\w+)/g) { $class = $2; print "$_ -> $class" for $1 =~ /\w+/g }' < your-file
Stéphane Chazelas's user avatar
1 vote
Accepted

Start of the line with regex in Ubuntu 22.04's gedit text editor

^ and $ work in gedit's Find and replace provided you tick the Regular expression box but gedit skips empty matches. ^$, ^ alone match an empty string so won't be replaced. x* matches 0 or more x's ...
Stéphane Chazelas's user avatar
1 vote

AWK match exact value from comma separated column in brackets

Using pcregrep: $ pcregrep -o1 '(\S*).*(\[(\d+,)*22(,\d+)*])' file Using awk: The following command may be used: $ nawk '$(NF-2) ~ /\[([[:alnum:]]*,)*22(,[[:alnum:]]*)*]/{print $1}' file If ...
Prabhjot Singh's user avatar
1 vote

AWK match exact value from comma separated column in brackets

Something like can do the work: awk -F"[][]" '$2~"22"{print }' <input file> here the delimiter is set to be [ or ] and check if second field contain 22 If you want the value ...
Romeo Ninov's user avatar
  • 17.2k
1 vote
Accepted

Rename file in Mac OS Terminal using Regex or translate from Windows Script

In zsh, from within the directory that contains those files, you'd run: autoload -Uz zmv zmv -n '*_ \((<0-999>)\)(* )—( * )(<1-12>)_(<1-31>)_(<1900-2100>)(.mp3)' \ '${(l[...
Stéphane Chazelas's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible