Questions tagged [regex]

Regex (or regexp) is known as regular expression matching of patterns, strings or characters in, for example, a large text file. Questions should be tagged as such whatever the programming language involved and the tag can also apply to command-line or graphical programs that have regex plugins or some regex capability.

Filter by
Sorted by
Tagged with
1
vote
0answers
18 views

Use exact match for apt install

I want to install g++-9 but something like: sudo apt install g++-9 Interprets g++-9 as a regex (probably because there is no exact match as I don't have the toolchain PPA installed) and installs ...
0
votes
1answer
22 views

Change regex's result order after sed as order of ls -v

I am working on 53 xml files (az-0.xml ~ az-52.xml). And I ransed '/<loc>/!d; s/[[:space:]]*<loc>\(.*\)<\/loc>/\1/' az-*.xml > AZ to get all stuff in <loc> and merge them ...
0
votes
1answer
25 views

Is exclamation mark(!) included in regex or glob?

In many articles they never included '!' in glob, which is wrong. So, where does ! truly belong to ? I have used ! in glob eg. ls lis[!ta]* does this mean ! is a part of glob?
1
vote
2answers
62 views

How to find a replace newline and commas in a file using regex function in gedit?

i have a text file : "postalAddress2": "Postal Address Line 2", "postalCity": "Postal City", "postalPostCode": "Postal Code", "postalState": "State", i need to remove the second column, ie, watever ...
0
votes
0answers
12 views

reader for ebup-files that can search text with RegExp?

I'm using Calibre E-book viewer (calibre %F) and E-book reader (FBReader) applications for reading epub-files, both can't find text inside files with Regular Expressions (RegExps). Maybe someone ...
1
vote
1answer
88 views

Asterisk problem with shell script

Well I have this problem. The problem is when I use an asterisk(*) as a paramenter to compare it with a regex expresion on a if statement. the regex expressions works fine until an asterisk is used. ...
0
votes
2answers
70 views

Reason for giving me more than 2 letters after sorting in regex

I have a text file that is named main.txt and it contains the strings: 1246 12 43 1 I have written the code: cat main.txt | egrep "[12-4]{,2}" I got the following output: 1246 12 43 1 Can you ...
1
vote
1answer
43 views

How to remove the first two characters of the file name when it is a hypen?

I have a bunch of mp3 files named - foo - bar.mp3. My goal is to remove the first hyphen and the first space on the terminal (Bash), which would give foo - bar.mp3. I tried it with rename 's/^..//' * ...
0
votes
1answer
50 views

Regular expression help

The strings to be matched are based on length. String S should be matched iff (|S| mod 3) > (|S| mod 2) where |S| is the length of the string. I've tried to find wrt LCM but I don't know how to ...
2
votes
2answers
70 views

Help with regular expression

Trying to build a regular expression that will match all strings that begin with word "med-" and end with ".opol.nei.com" like this one med-fe3-ua-kiol-33.opol.nei.com
0
votes
1answer
56 views

Regex for IP addresses [closed]

I'm currently learning regex will this detec any IP address? (((([0-9]|[1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9]|25[0-5])){1,3})(\.){0,1}){4} My previous one was this (([0-9]|[1-9][0-9])|(1[0-9][0-9])|...
-1
votes
1answer
65 views

Exclude match if there is word between two patterns

There is a file: cat file.txt dog blah crocodile blah dog blah cat blah crocodile blah dog blah crocodile blah dog blah cat blah dog blah cat blah crocodile blah dog blah crocodile blah mice blah cat ...
1
vote
2answers
45 views

Remove all file except multiple file by command

I have multiple file on my Ubuntu directory. I want to use a terminal command to delete all files except the files that are generated today. Today is 2019-10-15 and my files are: ... ...
4
votes
1answer
629 views

Find command with regular expressions

I am practicing a find command and the moment, and am curious about the usage of regular expressions in the find command(similar to grep). Does the command support it? If so, what are the options to ...
2
votes
1answer
993 views

How do you match any character in bash regex?

In a bash script, why does message='123456789' echo "${message//[0-9]/*}" display ********* but message='123456789' echo "${message//./*}" displays 123456789? All the documentation I've seen ...
4
votes
1answer
162 views

apt-file regex: find multiple packages at once using or

I'd like to search multiple packages at one using a regexp connecting pattern with logical or |. Assuming the two files /usr/lib/apache2/modules/httpd.exp and /usr/lib/apt/apt.systemd.daily exist: $ ...
0
votes
1answer
70 views

Valid linux command rejected in awk script

The test command is: $ if echo 'abcd' | grep -q '[a-zA-Z]'; then echo 'alpha'; fi From terminal I get 'alpha' as expected. But when I put the command in text file akpl.awk and run with $ awk -f ...
1
vote
1answer
83 views

filter data inside a file

I have a file that contains this type of data. Input: mstage1.service-ft.google.com:mstage1.service-ft.google.com mstage1.service.google.com mstage1.service.google.com:mstage1.service.google.com ...
2
votes
4answers
306 views

How to extract interesting piece of output in bash

My output of command is like: File Size : 23 kB File Size : 9.8 kB File Size : 9 kB File Size : 128 kB File ...
-1
votes
2answers
475 views

Grep and Regex: filter subdomains in a file

First of all sorry I should learn some grep and regex instead of asking that question but I have a little shortage of time for now. And I am definitely going to learn egrep eventually. So here is the ...
0
votes
0answers
38 views

Running Different GRUB2 Configuration for Multiple Diskless Clients?

My setup has one head node which hosts a bootable image, which many compute nodes PXE boot from using grub. The issue is because of the varying hardware of the various nodes, I need different grub ...
1
vote
0answers
606 views

geany editor match newline

I have a plain text file with a large number of lines with a blank line between each pair of lines. I want to remove the empty lines. I am trying using the Replace dialog with regex, to replace '\n\...
1
vote
2answers
64 views

How do I perform a exact match in man page?

For exmaple, I open man page of tar and I want to locate -z quickly. But when I type /-z, things like -i, --ignore-zeros also get matched. So I have to press n several times to reach -z. However, I ...
0
votes
2answers
195 views

Find unicode by its code via grep

How find a symbol by code of Unicode? E.g. try find a space ('\u20' or '\u0020') in the second line: echo -e "u20\n \nfoo" |grep "\u20" - found the literal u20, not the space line. echo -e "x20\n \...
0
votes
0answers
76 views

Regex for /etc/passwd Content

I have a collection files from many systems in my enterprise in a store directory (/store/) and I wanted to find all of the passwd files and cat them out to a single file. Intuitively, the command I ...
1
vote
1answer
101 views

Rename multiple folders, using regex

As the title says, I'm looking for a command / tool - preferably something running from the terminal (I'm using Ubuntu on a remote server), that can replace a specific part of multiple directories at ...
7
votes
1answer
697 views

RegEx with \d doesn’t work in if-else statement with [[

i wrote the following script. It will be used in a build process later. My goal is to decide whether it's a pre release or a release. To archive this i compare $release to a RegEx. If my RegEx ...
1
vote
1answer
100 views

How remove repetition of content?

I have a file aq.txt contain the following content: WP_021815421.1 OG5_132922 deth|YP_182312 3 -07 42.35 81.7 WP_021815427.1 OG5_128110 rbal|NP_868155 1 -55 50.72 53.2 WP_012456834.1 ...
0
votes
1answer
438 views

Regex for fail2ban config file to match pregreet lines in mail.log

The lines in mail.log to match are like: May 6 10:06:16 mikes-serverbox postfix/postscreen[15486]: PREGREET 14 after 0.1 from [173.225.99.104]:57130: EHLO ylmf-pc\r\n May 9 11:36:36 mikes-...
1
vote
1answer
57 views

How to replace and edit content of file?

I have a file which contains the following content: set0027: set0027_100-250 set0027_1-150 set0027_50-200 set0038: set0038_100-250 set0038_1-150 set0038_50-200 I want to modify it in the following ...
1
vote
1answer
39 views

Trouble getting rename working with regex groups

Folder of files that need to be changed to YYYY-MM-DD.pdf but currently are MMDDYYYY.pdf This is what I came up with but it's not working rename -nv 's/^(\d{2})(\d{2})(\d{4}).*/$3-$1-$2.pdf/' *.pdf
1
vote
1answer
752 views

E: Unable to locate package regex

I'm trying to use the regex package in my python script, using: import regex as re and the package is missing: $ ./lula2.py Traceback (most recent call last): File "./lula2.py", line 13, in <...
-1
votes
1answer
81 views

Write a regular expression which catches user $HOME in shellscripting

I'd like to write a regex in shellscript which would compare the user input path to user$HOME. Then it would raise an error in case the user input path contains the user $HOME. The home folder ...
1
vote
1answer
539 views

Negative to positive number range in regex in bash scripting

I am trying to make a regex expression that will validate a number that is in the range of -100 to 100. I made this regex expression: (^-[1-100]* |^[0-100]*) but it doesn't work as expected. I am ...
4
votes
2answers
532 views

Extracting names from filename in Bash

I have a directory filled with thousands of files in the format LastnameFirstnameYYYYMMDD.pdf. The last and first name will always been in title case. I'd like to extract the last name so I can move ...
0
votes
2answers
1k views

RegEx - How to extract second matches using grep

How to extract second numbers in this text using grep command in ubuntu. filename : Results.html?owner=12345 14219,98.2,31-s,19225 39219,92.7,31-s,29225 ouput desired : 12345:98.2 12345:92.7 ...
1
vote
1answer
824 views

grep doesn't work as expected

I'm trying to understand how grep deciding to take $ as regex, or as a searchable character. My results show that grep is inconsistently deciding what $ means. As such, I made a basic example: $ ...
1
vote
1answer
140 views

How can I grep patterns only inside files with a specific file name?

I spent plenty of time searching for an existing question about my issue but I falied to find any solution for this case in specific. I apologize in advance if there is an existing thread/question ...
1
vote
3answers
88 views

What is the correct way to format this grep?

I am having trouble figuring out where to place the \ in this command. grep "^D.*\(A1|A2|A3\)$" input.txt > output.txt I'm searching for each line that starts with a D and ends with A1, A2, or ...
0
votes
1answer
95 views

Gnu sed regular expression extension, how to type these two characters?

This may be a stupid question, but I'm not sure and just want to confirm. Gnu sed has some regular expression extensions that work in both BRE and ERE mode. The following are an excerpt from the sed ...
2
votes
1answer
72 views

how to create a regex string where you don't know what to escape

I have a passwd file with the line containing root being: root:6UZSjeWUui3JQ:0:0:root:/root:/bin/sh I want this line to be changed to: root:$1$dog$cNv/OuAd7CMNdrhWsHXAR.:0:0:root:/root:/bin/sh ...
0
votes
1answer
63 views

How to verify the position of characters from the column? [closed]

I have a column MBI contains 11 characters. Out of these 11 characters: 2nd, 5th, 8th, and 9th characters will always be a letter. Characters 1, 4, 7, 10, and 11 will always be a number. The 3rd and ...
0
votes
2answers
290 views

Regex “.*?” giving same output as “.*”

This the file I am using: Shane is a little to play ball small silly When I use egrep 's.*l' new I am getting the output as Shane is a little to play ball small silly When I use egrep 's.*?l' ...
1
vote
1answer
90 views

Regexxer stopped working - it doesn't find the string

Regexxer is a brilliant search-replace tool for multiple files, but suddenly it stopped working August 10. I posted this on the Regexxer bug page: I used this brilliant program less than 20 hours ...
0
votes
1answer
361 views

Bash case match trouble with mixed numbers and letters

I am trying to allow a user to enter in a size that will be used in fallocate, so I need to make sure text is entered as 1G, 8G, 512M, etc.. I have the following code below; however, all correct ...
0
votes
1answer
59 views

Need help on an egrep regex

I am trying to create an egrep command to grep the number of lines containing a specific text from a text-file but seem to have an error somewhere. The text-file contains several thousand lines and ...
10
votes
2answers
5k views

sed with PCRE (like grep -P)

I am happy that grep does support Perl Compatible Regular Expressions with the -P option. Is there a reason why the tool sed does not have this feature?
1
vote
1answer
3k views

How to filter a regex (exclude special characters)

Let's say that I need to filter all my files' names that don't include special characters. ASDA123fasf - would pass asasdasd*dasd - wouldn't pass
1
vote
1answer
11k views

How to find a line starting with 'a' and ending with 'c' using grep?

I have a file named newfile. The contents of this file are: abc xyz abc Now I want to find lines which start with a and end with c. I enter the following command but the results are not the same as ...
6
votes
2answers
312 views

How do I search for lines in a file that only contain ASCII characters and then act on them?

I have a text file that looks like this: English words only English and 日本語 日本語のみ English words only English and 日本語 日本語のみ English words only Also English words only English and 日本語 日本語のみ English ...

1
2 3 4 5 6