New answers tagged regular-expression
0
votes
Accepted
Open specific URLs in certain app?
Use a wrapper script:
#!/usr/bin/bash
url=$1
if [[ $url == *youtube.com/watch* ]] ||
[[ $url == *youtu.be* ]] ||
[[ $url == *vimeo.com* ]] ||
[[ $url == *instagram.com* ]] ||
[[ $url == *...
1
vote
Perl RegEx one-liner that outputs all matches from one line of STDIN
python would be much too verbose as a CLI one-liner
For what it is worth, seeing the complex:er perl in @Stéphane's answer...
# copy & paste the following lines into a shell to try it out
echo '&...
5
votes
Accepted
sed: why my regex does not work correctly
[^\"] means “any character except \ and "”; so nothing ends up replaced. You’ll get the result you’re after if you remove the backslash from the bracket expression:
sed -e 's/\"\([^&...
5
votes
Accepted
Perl RegEx one-liner that outputs all matches from one line of STDIN
echo '"this text", " ", "is in speech marks"' |
perl -lne 'print for /"(.*?)"/g'
Or:
echo '"this text", " ", "is in speech marks&...
1
vote
Extract email addresses from line, with multiple email addresses per line
Using any awk, assuming the input is as simple/regular as in the provided example:
$ awk -F'[<>]' -v OFS=', ' '{for (i=2; i<=NF; i+=2) printf "%s%s", $i, (i<(NF-1) ? OFS : ORS)}' ...
0
votes
sed: invalid usage of line address 0
The line address 0 is a non-standard extension of the GNU implementation of sed that allows doing things like 0,/pattern/ x to run the x action on lines from the start of the input(s) (or start of the ...
1
vote
sed: invalid usage of line address 0
This will robustly do what I think you want, using any awk:
awk -v d="$(date '+%d/%b/%Y' --date='30 days ago')" '
f || ($0 ~ "^"d":([0-1][0-9]|2[0-3]):[0-5][0-9]$") { ...
0
votes
How to make Perl half/full width-insensitive regular expressions?
What is the easy way to write /4|4/ ?
Here's a long one-liner:
perl -COA -lwe "@c=('A'..'C','x'..'z','0'..'9'); $rs = sprintf'[%s%s]', join('',@c), join('',map chr 0xfee0+ord, @c); print $rs; $r ...
8
votes
sed: invalid usage of line address 0
When you want to use a different character than / for a regex in an address, you have to prepend a backslash to the opening character.
sed "0,\~$date_pattern~/d" file
This still doesn't ...
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
regular-expression × 2836sed × 901
grep × 735
bash × 445
text-processing × 372
awk × 354
shell-script × 249
linux × 225
shell × 157
find × 142
perl × 139
command-line × 80
vim × 78
rename × 72
wildcards × 71
replace × 59
scripting × 54
string × 53
quoting × 52
files × 46
macos × 46
search × 46
filenames × 29
posix × 27
xml × 26