Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [regular-expression]

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

5
votes
1answer
181 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
3
votes
1answer
94 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
1answer
103 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
1answer
542 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 ...
1
vote
1answer
249 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
1answer
54 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
5k 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
1answer
914 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-...
0
votes
1answer
60 views

Complex string replace - multiple files, multiple different strings, must include certain text

I have a number of XML files (Atlassian Confluence space exports FYI), that I need to parse through to replace certain strings, as long as the line begins with a set string. Here is an example of a ...
0
votes
1answer
68 views

Loop through many folders and do calculations with files with similar pattern in bash

I have several folders each containing several .nc files. I want to loop through all folders and for each folder do some calculations (mergetime) using cdo on files that have similar pattern. So far I ...
0
votes
1answer
35 views

How can i choose uppercase words with regexp

Hi i want a regular expression match all words with first letter uppercase. But there is this greedy problem. If i use \<[[:upper:]].*\> It will start matching at word starting with uppercase ...
0
votes
1answer
53 views

Insert new text in the middle of a file replacing old text without re-inserting the same things over and over?

I have a file that I want to update relatively frequently. What needs to be done is that a specific part of the file would be changed to include some more lines. I am doing it with sed and \a option: ...
0
votes
1answer
31 views

log processing/entry deletion, multi-pipe (grep sed grep), log traversed twice. can this solution be improved?

Is there a cleaner way? A single pass of the large input.txt file would be preferred. Solution so far: grep -e "\[.*fred" input.txt |sed 's/.*\[\([^]]*\)\].*/\1/g' |grep -vf /dev/stdin input.txt ...
0
votes
1answer
65 views

Regex Group Match help

Using this regex ;(31055\d*)|^;\d{10}(\d{7}) How do I get the second part of the regex after the "|" to report as Group 1 using the test string of ;1000000000146691301? The regex is working but I need ...
0
votes
1answer
200 views

regex to replace a word in a block in a file?

If I have: <Directory /> words allow bus </Directory> Is there a regex that can replace allow with something else and keep the other words and the block intact? So it should look ...
0
votes
1answer
43 views

Grep: find all emails that don't have the pattern

I have a directory with a bunch of files and each file contains millions of emails. I need to get all the emails that don't fit with this pattern x.y@enron.com x and y are letters. I have this ...
0
votes
1answer
128 views

How to disable an AutoKey script while in a specific program?

This is a regular expression question. I use AutoKey on Debian to execute custom commands with hotkeys, such as Super-E to toggle Nautilus. But sometimes I run a VM in VirtualBox and AutoKey is ...
0
votes
1answer
154 views

Remove <div> blocks matching a string from a huge html file

I am on Mac and I want to remove multiple <div> blocks from a html file that match a certain string. I tried to use sed for it the following way, but failed: First I escaped all the symbols in ...
0
votes
1answer
162 views

wget output based on regex

I have a very long list of files in the following format: https://server.com/Nonsense%20text%20Actual%20Filename01.ext<br> https://server.com/Non%20essential%20text%20Actual%20Filename02.ext<...
0
votes
1answer
46 views

Invert last two subfolders of the directory structure

Basically, I request a unix way (bash, perl, etc) to invert the last two subfolders, like in this windows question: https://superuser.com/questions/221/how-can-i-invert-a-directory-structure This is ...
3
votes
0answers
45 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
158 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
781 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
0answers
23 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
147 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
0answers
323 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 ...
1
vote
0answers
58 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
82 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
75 views

Sqlite: replace a string modelID1/modelID2/modelID3 with name1/name2/name3/

My goal is to read the macOS Photos.app database to find out the paths of the included photos. The album and the parent folder whose name is in the RKFolder table can be determined for each photo. ...
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
849 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
0answers
173 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
59 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
0answers
172 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, ...
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
290 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 ...
0
votes
0answers
34 views

sed command to insert between two strings that are returned from another sed command

I have a YAML file that's about 25K lines and I have about 450 instances where I need to insert between two specific lines. Here's an example of the file entries: - changeSet: id: ...
0
votes
0answers
31 views

Commenting out a specific host configuration in a Nagios configuration file

I have lots of Nagios configuration files like the one below in a directory, and I need to remove a host from monitoring. define host{ host_name nmo use aix-server alias hostgroups +...
0
votes
0answers
45 views

Remove all words from a file except certain words

I have a file which represent a list of SQLs where caluses. I want to remove everything that is not the columns names, and, or and where(case insensitive). In addition if it can also remove new lines ...
0
votes
0answers
40 views

Change text color in PDF files

I want to change some Text-Coloring by regex search in one or more PDFs. for example i want to change the color of all appearances of "A[0-9]+.[0-9]" like A120.1, A600.0 and so on. is it even possible ...
0
votes
0answers
37 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 ...
0
votes
0answers
101 views

Why does fail2ban not trigger my custom filter?

fail2ban-regex verified that my filter matches Jan 14 07:39:41 myhost01 sshd[26433]: Connection closed by authenticating user root 127.0.0.1 port 56216 [preauth] 68 times inside auth.log, but fail2ban-...
0
votes
0answers
24 views

How to create a regex matching a custom string at the beginning of line while ignoring all preceding whitespaces via ag silversearcher?

Give an example file with the content: // find me val ignore me = "" // I should not be found // find me // find me I want to find all the lines with find me using ag silversearcher. ...
0
votes
0answers
23 views

How to iterate pattern by other one?

I have the bellow output. I try to iterate same times the Date and Time: Month Day Year HH:MM:SS for each Application n.n string found it. =========================================================...
0
votes
0answers
99 views

How to configure which characters are allowed in CentOS usernames

In systems such as Debian, there is a file /etc/adduser.conf which includes directive NAME_REGEX that can be used to define which characters are allowed in a username. Is there a way to do this in ...
0
votes
0answers
112 views

regex and grep: match all letters in a list

Im trying to find the phrase 'Capital Idea', case sensitive, in a file. The phrase can be on one line, across multiple lines, and have letters in between. For example, Match: Capital Idea Capital ...
0
votes
0answers
102 views

Removing lines from file matching 2 strings

I am trying to remove lines in a file that contain 2 strings. I am using: perl -i.tmp -ne "print unless /$STRING_A/ and /$STRING_B/" /foo/bar/file.txt The result is that all lines from the file ...
0
votes
0answers
151 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
0
votes
0answers
159 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
0
votes
0answers
68 views

Regex for a non-fixed pattern

I am trying to come up with the right regex (compatible with python) that would match a file that contained sample input as follows: On the third day of Christmas my true love sent to me: three ...