Questions tagged [regular-expression]

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

117 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3
votes
0answers
73 views

Renaming files with vidir (moreutils)

I'm trying to use vidir from the moreutils package and I have the following issue: When I load the files I want to rename with vidir like this: $ vidir or like this: $ find -type f | vidir --...
3
votes
0answers
185 views

How do backreferences slow down regular expression search?

Let's say I have a text file with 20 chars per line like this: wertzuiopasdfghjkl< asdfghjkl<yxcvbnm,.- <yxcvbnm,.-123456789 1234567890QWERTZUIOP QWERTZUIOPASDFGHJKL< and so on ... and ...
3
votes
0answers
799 views

what is the correct regexp for mysql filter in fail2ban?

I use the default filter file /etc/fail2ban/filter.d/mysqld-auth.conf for fail2ban service. But there are some errors in file /var/log/fail2ban.log as: Found a match for '150815 10:42:54 [Warning] ...
2
votes
1answer
73 views

Bash: Regex for comparing file path

I want to check if an input string matches whitelisted file paths, then only I want to perform some operation. I am doing something like this path1="mydir/**" path2="mydir/testing" [ [ "$path2" =~ "...
2
votes
1answer
224 views

mosquitto bruteforce fail2ban failregex

I am trying to write fail2ban filter to block bruteforcing IP addresses which are trying to subscribe to username/password protected mosquitto service by guessing username/password combinations. On ...
2
votes
0answers
31 views

Interpolated and literal Perl strings in Nano are incorrectly highlighted

I am trying to improve Nano's syntax highlighting for Perl, but I have run into an interesting dilemma. Perl uses single quotes for literal strings, and double quotes for interpolated strings. The ...
2
votes
0answers
198 views

wget regex options ignored over ftp

Wget specifies the --accept-regex and --reject-regex options for limiting recursive downloads. I'm unable to get them to work with an ftp connection. For example, I would expect --reject-regex='.*' ...
2
votes
2answers
148 views

Replace characters in matched line

I have some text with ip inside it. I'd like to replace each digit in ip which is not followed by "SpecialWord" with some other character. There is can be more than one ip in each line. For example: ...
2
votes
1answer
112 views

Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)

I want to edit a file called trial.fastq with the following format: @NAME123.15.1 15 length=151 GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC +NAME123.15.1 15 length=151 AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH ...
2
votes
2answers
394 views

How to use command-line argument as awk regex matching expression?

I have the following awk script: #!/bin/awk -f BEGIN { FS = ""; } value ~ "MYVALUE" # silly test { print "1 - " substr($0, 235, 12); } $235 ~ "M" { print "2 - " substr($0, 235, 12); } ...
2
votes
3answers
744 views

awk with regex for delimiter

I want to get the first word in every line from a file. Unfortunately a lot of lines begin with space(s). So I try to get the firs word with the following: awk -F'[ \t]+' '{print $1}' < MyFile.txt,...
2
votes
1answer
604 views

adding a regexp filter to block a subdomain and TLD in sendmail

Running Sendmail Version 8.15.2 on Fedora 24 and lots of spam is coming in from (subdomain).(manydomains).us. I'd like to add a filter like what's available in the access file to block and .us TLD's ...
2
votes
2answers
140 views

sed match word1 and word2 to get word in between

Im having issues with trying to pull an ip address our of a log file call full. This is what the line in the file looks like [2016-11-10 11:22:42] NOTICE[24518] chan_sip.c: Registration from '"...
2
votes
0answers
353 views

convert attachments of type winmail.dat (TNEF) to “real” attachments in stored email messages, recursively in MailDir

Some email messages contain the attachments in a format called TNEF (Transport_Neutral_Encapsulation_Format). This attachment is usually called winmail.dat. Extraction tools exist for linux, but ...
2
votes
1answer
1k views

LFTP exclude file extensions

I am trying to mirror directories with lftp but I don't want to download filetypes that are notoriously large like .mp4 and .swf. But I am having trouble with the regex - and seeming like the exclude-...
2
votes
0answers
188 views

What is SELinux's regex type?

I'm trying to locate all files on my system matching an SELinux file context (fcontext). These contexts are specified using some regex, and I'd like to use find -regex ... to the same effect. However, ...
2
votes
2answers
893 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
1
vote
0answers
24 views

Find + regex: looking for a file name with multiple extensions, but missing the basic filename.jpg

I'm both a regex & SE Unix and Linux newbie, so I hope I'm doing everything right. I'm looking for files that have a name inside of the filename, and could have different extensions. I based my ...
1
vote
0answers
161 views

Regex matching comma-separated list of values, trailing comma not allowed

I want to match: aaa aaa,bbb aaa,bbb,ccc But not a list with a trailing comma. My current regex: (\w{3},?)+ also matches lists with trailing commas (aaa,bbb,). I was thinking I could also do: (\w{...
1
vote
0answers
68 views

sed command is replacing the replaced text?

I am writing a bash script to rename icons. Specifically I am trying to change "icon-close-m" to "icon-close icon-size-medium" in HTML files. (though it could contain any substring besides "close", as ...
1
vote
0answers
94 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...
1
vote
0answers
46 views

How can I regex match-and-replace _all_ on-screen text?

I need a way to replace an on-screen pattern with another string, regardless of what places that text on the screen. Maybe I can live without user input being replaced, but anything that comes from ...
1
vote
3answers
213 views

How to move a line from a file to the other file on the basis of pattern matching?

I want to move lines from a text file into another text file. Those lines contain a word beginning with an underscore. This word is located on the sixth field of the lines; fields are separated with ...
1
vote
0answers
27 views

How to search email with Jämsä for Jämsän in Thunderbird?

Finnish language has many many endings, but I cannot search easily the base word, etc by Jämsä. For instance, searching Jämsä will not give Jämsän in the basic Thunderbird search. A basic regex ...
1
vote
0answers
958 views

Gedit: How to insert backslash \ in search and replace regex

I'm trying to comment out some lines in c++ by matching them with a regex, and replacing with the match preceeded by \\. But instead, gedit performs no replacement, and the search+replace dialog gives ...
1
vote
1answer
298 views

How to grep non consecutive patterns

How to grep non consecutive patterns... I run this command. grep -B 1 -A 2 "field-2-value" inputFile.txt |grep -v "field-3" which yields these 4 outputs. [field-1]xxx[/field-1] [field-2]field-...
1
vote
2answers
178 views

Using Uniq -c with a regular expression or counting the number of lines removed

I have a tab delimited file with information in it about genetic material. Some information is cut into a smaller tab file with some of the columns extracted, and uniq is used to ensure there are no ...
1
vote
0answers
181 views

Apache redirect rule using regex

Hello I am trying to do a regular expression for an apache rewrite rule that handle request with no slash at the end and no extension an example https://www.some.thing.com/life-health-insurance ...
1
vote
0answers
89 views

Emulating git status --ignored in non-repository folder

This might be in essence a duplicate of this question, however the perl script provided did not work in my case as far as I can tell. There are also many questions about finding multiple patterns, but ...
1
vote
2answers
373 views

Remove multiple regular expressions from variable with sed

I'm sure this is pretty simple but I can't seem to find a good example. I'm trying to parse /proc/1/exe to find the init system of a box. Exe is a symlink to the init system, but it has quotes in it ...
1
vote
1answer
55 views

How to match string with regexp and conditionally do stuff with capture groups

The idea here is to change remotes from http to ssh in all git repositories find / -type d -name '.git' 2>/dev/null | xargs -I {} $SHELL -c \ 'cd $(dirname {}) && echo $(pwd) > /tmp/log....
1
vote
1answer
6k views

Ansible, attempting to get specific regex pattern to work with lineinfile module

As per my question above: "Ansible, attempting to get specific regex pattern to work with lineinfile module" Essentially, I'm trying to get it to work in a single play as opposed to 2 separate plays, ...
1
vote
3answers
43 views

retrieving host name from email address

I am trying to go through individual emails and retrieve the host name. Each email has a To: section with an email address "abc123@aol.com". I'm trying to retrieve just "aol.com" Eg: To: abc123@aol....
1
vote
0answers
1k views

how to exclude range of numbers using regular expression

I'm trying to write a regular expression in order to cover all numbers starting with 1809 and excluding some ranges: Ranges needed to be excluded Starting with 1809 and followed by: 201,203,205,212,...
1
vote
0answers
298 views

Need .htaccess Rewrite Rule To Remove Trailing <br%20/>

I have links that for some reason have a trailing <br%20/> and I don't know where they are coming from to try and fix them. So I need a general rewrite rule to remove them so the links won't ...
1
vote
1answer
361 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...
0
votes
0answers
26 views

Using subset in sed for replace with regex

Well consider some data that looks like "2019-12-12 00:00:01","2012-01-01 01:01:01" I wish to replace it so they are valid datetime json values: "2019-12-12T00:00:01+01","2012-01-01T01:01:01+01" I ...
0
votes
1answer
48 views

How to list all mounts that start with a given prefix/root

I am trying to look through /proc/mounts and return all mounts that start with a certain prefix or base directory, eg. /run/media. Right now one prefix is fine, but in principle it would be nice to be ...
0
votes
0answers
34 views

How can I make / \ replacement more efficient in console?

In a Windows/Linux environment, I'm having trouble with copying and pasting file system links to AND from! Right now, I use Gitbash (uses / for folder/subf ) which has been helpful. BUt it wants ...
0
votes
0answers
32 views

Large file processing performance

I did a simple performance test of csv processing a while ago, and want to share results with community, maybe you can point out, what test could be more precise and fair. Firstly i took out 42 MB ...
0
votes
1answer
68 views

Find and replace the columns of matched and non-matched lines with a character

I have a csv file with a bunch of numbers ranging from 500 to 500,000 and would like to replace the matches with 1 and mismatches by shifting the mismatched content to right simultaneously shifting ...
0
votes
0answers
20 views

grep -f not working with file

I have a file with having patterns separated by new line characters. which matches the patterns i want to find from a file. but when i run command grep -f patterns_file words_file It gives no ...
0
votes
0answers
25 views

How to look for directory in http address

I'm trying to create a regex formula in shell script which will allow me to find desired folder in HTTP directory. Let's assume that this is the address: ftp://google.com/directories/ In this ...
0
votes
1answer
113 views

Ansible replace first occurance on file

I am using Ansibles replace module, I want to replace only the first occurrence in the file. I have example string: example.string.in.my.text=test.@@sometext@@ I wish: example.string.in.my.text=...
0
votes
1answer
78 views

How do i use regex in shell script for replacing capture group content

Inputs files in multiple directories and want to change the exiting index name to index = windows_pr and index = windows_np. The WinEventLog blocks shown are all in the same file called inputs.conf ...
0
votes
2answers
49 views

Grouping and capturing works for toy problem, not real world

Toy problem: $ echo "foo <a href="/topic/null-hypothesis/" data-sc="text link:topic link">Null hypothesis</a> bar" | sed -E 's@.*<a href=/topic/[^>]*>([^<]*)</a>.*@\1@' ...
0
votes
1answer
36 views

match groups with an inverted match

I need to extract with -o1 a group that is matched in lines that do not contain a string. If I use -v pcregrep does not match any groups - which is reasonable: I'm asking to group-match something in ...
0
votes
1answer
33 views

Change hostname in tnsnames.ora file

I'm trying to write a script to update just the hostname in the tnsnames.ora file. I'm needing the entry to work case insensitive. For example ${DBNAME} is lowercase database name and in my tnsnames....
0
votes
1answer
23 views

Trying to parse a string in BASH for [ - _ ]

I have a BASH script that allows a user to specify a jobname. Right now we except everything. We feed this jobname into another executable that can only accept the following formats: job_name, ...
0
votes
1answer
22 views

sed: Change a variable-length numerical value for an indeterminate string

The string I need to modify in a hardware driver .conf file is as follows: options rsi_sdio dev_oper_mode=13 Looks simple enough, but the developers are happy to change this string which will break ...