Questions tagged [regular-expression]
Regular expressions are a means of matching a pattern of characters within a string.
2,832 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
4
answers
627
views
Extract email addresses from line, with multiple email addresses per line
I have a text file that mixes names and email addresses, in a comma-separated list.
First Person <[email protected]>, Second Person <[email protected]>, Third <[email protected]>
...
-1
votes
1
answer
127
views
sed inplace in selective block
I have a dir containing logstash config files
these files have filter blocks, and sometimes nested child blocks
need to match whole filter block
filter { any text till final matching closing brace for ...
3
votes
6
answers
211
views
regex to find text plus trailing 10+ spaces; sum of two matches' lengths is part of matching condition
I'm trying to clean files that are copy/pasted versions of my Cygwin (mintty) terminal running bash1. Usually, the input and output are separated by a linefeed ('\n'), as expected. However, when I ...
8
votes
1
answer
585
views
Is there any way to see the string that was matched in grep?
I'm not talking about -o option.
Posix says:
The search for a matching sequence starts at the beginning of a string and stops when the first sequence matching the expression is found, where "...
-1
votes
3
answers
92
views
How to remove markdown links from headers with sed?
I'm trying to use sed to remove links like and leave just the title:
## [Some title](#some-title)
This is my command:
sed 's/^\(\#*\) *\[\([^\]]*\)\].*/1円 2円/'
I expect to have just the text without ...
0
votes
0
answers
39
views
Borg files in `~/.local/share/` occur a "dir_open: [Errno 13] Permission denied" error
General overview
With BorgBackup, I do a backup of my whole $HOME. However, some files (all located on ~/.local/share/) occur a rights error. Probably cause it’s ephemeral files belonging to root, I ...
1
vote
3
answers
343
views
How to delete lines with sed if they contain a phrase?
I tried this
sed -i '/^already satisfied$/d' loggocd.txt
but lines like this one
Requirement already satisfied: cryptography in /home/go/.pyenv/versions/3.9.1/lib/python3.9/site-packages
are not ...
-3
votes
1
answer
79
views
How to extract an unknown number of file lines between two regex patterns?
For example I have file with many of lines and it has such part
...
pattern1
line1
line2
line3
pattern2
...
how can I extract line[1-3] via one-liner command (awk or something like that)?
2
votes
4
answers
164
views
Grep (BRE) on surrounding delimiters w/o consuming the delimiter? Counting delimiter-separated strings between filename and extension
I have a dataset of images labeled/classified by characteristics, where an image can have more than one label. I want to count how many of each identifier I have. A toy dataset is created below, with ...
-1
votes
3
answers
184
views
grep capture from beginning until first 2 chars found
I have this list:
list="aa bb cc dd ee ff ab cd ef"
What I'm trying so far:
$ grep -o "^[^cd]*" <<<"$list"
aa bb
Expected output:
$ grep -o "^[^cd]*" ...
3
votes
3
answers
258
views
Sed - Help Matching with Multi-Line Match
I am fairly new to regexes and it appears I am missing something in my understanding. I have the following file, and I am trying to insert a value if it is missing.
The file looks like
[composefs]
...
5
votes
1
answer
135
views
Sudo regex 1.9.16p2 - not working
I installed sudo v1.9.16p2 on a RHEL 9.5 server which should support regex matching. As a test I created a test user (testuser) and created a (simple?) rule in /etc/sudoers for this test user that ...
1
vote
2
answers
478
views
sed in makefile is not working as expected when using regex
Got a makefile whith this command which convert folder names on ./cmd/ from snake_case to PascalCase
test:
@for f in $(shell ls ./cmd/); do \
echo $${f}; \
echo $${f} | sed -r 's/(^...
0
votes
5
answers
113
views
Match multiple vars across two lines and delete entire entry
MATCH1.MATCH2 {
always same MATCH3
}
All three MATCH(es) must match.
input:
foo.bar {
always same bus
}
1.2 {
always same 3
}
a.b {
always same c
}
i.ii {
always same iii
}
b.2 {
...
0
votes
4
answers
111
views
sed \(.*\) matches more characters than originally intended
I have a list of celebrities with their place names as,
Bill Gates Manhattan
Elon Musk California
Narendra Modi Delhi
Donald Trump Washington
I like to rewrite with the location name in the middle ...