Skip to main content

Questions tagged [regular-expression]

Regular expressions are a means of matching a pattern of characters within a string.

-1 votes
1 answer
63 views

sed: why my regex does not work correctly

So, I'm facing a curious issue with sed; I have reduced my problem down to the following. Why does sed -e 's/\"\([^\"]*\)\">/\1/' <<< '["\{">' return ["\{&...
Grass's user avatar
  • 101
-2 votes
2 answers
80 views

Perl RegEx one-liner that outputs all matches from one line of STDIN

Here is a silly example that effectively illustrates what I need: echo '"this text", " ", "is in speech marks"' | perl -lne 'print "$1" if /"(.*?)"/' ...
Signor Pizza's user avatar
2 votes
3 answers
340 views

sed: invalid usage of line address 0

I need to keep only last 30 days events in the log and remove other data. Log has timestamp (date +%e/%b/%Y:%H:%M) and next line values like 01/Jan/2025:00:00 value1 value2 ... 01/Jan/2025:06:45 ...
Aleksey's user avatar
  • 75
3 votes
2 answers
175 views

Embedded special characters skewing sed output

The Issue I've been parsing a file with sed trying to tweeze out the desired data. This has worked fine for most lines in the file but there appears to be some embedded special characters that are ...
Gandalf's user avatar
  • 33
0 votes
5 answers
771 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]> ...
hugomg's user avatar
  • 6,095
-2 votes
1 answer
140 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 ...
Sollosa's user avatar
  • 2,009
3 votes
6 answers
220 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 ...
bballdave025's user avatar
8 votes
1 answer
596 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 "...
Mark's user avatar
  • 99
-1 votes
3 answers
100 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 ...
jcubic's user avatar
  • 10.4k
0 votes
0 answers
47 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 ...
fauve's user avatar
  • 1,529
1 vote
3 answers
358 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 ...
MJoao's user avatar
  • 47
-3 votes
1 answer
89 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)?
Aleksey's user avatar
  • 75
2 votes
4 answers
173 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 ...
bballdave025's user avatar
-1 votes
3 answers
190 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]*" ...
Zero's user avatar
  • 39
3 votes
3 answers
273 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] ...
adam's user avatar
  • 33

15 30 50 per page
1
2 3 4 5
190