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 ...
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 ...
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 ...
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
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 ...
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 ...
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 ...
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[...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
regular-expression × 2748sed × 874
grep × 710
bash × 425
text-processing × 365
awk × 346
shell-script × 244
linux × 222
shell × 153
find × 137
perl × 132
command-line × 79
vim × 75
rename × 71
wildcards × 69
replace × 59
scripting × 52
string × 52
quoting × 51
files × 45
search × 45
macos × 41
filenames × 29
xml × 26
posix × 25