Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
2answers
23 views

Can't run parallel zgrep with regex

When I run this: find . -name "my.log*.gz" -print | \ parallel zgrep -e "\(text1\|text2\).*Exception" to find all lines that match /(text1|text2).*Exception/ in all files in the folder, I get this ...
4
votes
3answers
321 views

How do I search a file using “less” for a value with a decimal point?

So I less my file: less myFile.log Then I try to search for a value: /70.5 I've since learned less uses regex, so . is a wildcard. I've tried to escape it with no success.
0
votes
0answers
32 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
3answers
54 views

How to grep a line who has execution time greater than X

I have this line in my log invokeSuperLambda execution time:xxs Where xx is the time of execution and s is a static letter When I run this on my log file grep -a "invokeSuperLambda execution ...
2
votes
2answers
54 views

Having trouble parsing a csv file from the commandline

I have a CSV file that I've been working on for most of the day and I'm not having any luck getting it parsed properly using a Regex with awk. awk is not processing the Regex as expected. Here are ...
0
votes
1answer
26 views

Merging PDF files with similar names

I have a folder populated with PDF files in this format: SI-T-xxxxxx.pdf SI-T-xxxxxx-sol.pdf SI-T-yyyyyy.pdf SI-T-yyyyyy-sol.pdf and so forth, with the middle part being digits. I want a way for ...
0
votes
3answers
43 views

Linux sed command replace two lines having spaces and special characters using regular expression

I have one file having following example text. "list-value": { "object-value": { "value": "example-value-123" } } I want to change value text "example-value-123" by matching pattern ...
3
votes
4answers
195 views

Replace a string in a file preceeded by another string

I have a bunch of config files looking as follows: reader_0 = newcamd({ name = "Oct 1", host = "hostname 1", port = 27020, user = "UNAME", pass = "password1", key = "0102030405060708091011121314", })...
1
vote
1answer
14 views

Why might re.search process these patterns differently?

I regularly use sagetex, which is written in python. One of the scripts in the package defines a variable like this: ignore = r"^( _st_.goboom|print 'SageT| ?_st_.current_tex_line)" The script ...
0
votes
3answers
29 views

using awk to modify field with condition

INPUT New,9,1 Old,11,0 OUTPUT New,09,1 Old,11,0 I would like to append to filed number 2 after first , in case if it's single digit so i would like to add 0 before the digit as the output shown. ...
2
votes
1answer
41 views

How can I grep for empty functions?

I'm recursively looking in a directory for all functions containing only a blank one-line comment, such as the following: public function index() { // } I tried grep -PR "//$" * with no luck.
1
vote
1answer
43 views

Using sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG files

I would like to ... replace the hexadecimal code for URL (id) in all SVG files insert/add the new lines of SVG codes after <svg ...>, using Regex. Input: <svg xmlns="http://www.w3.org/...
0
votes
2answers
36 views

delete pattern at least 5 numbers non consecutive

I have a file with about 7 million passwords with mixed Lower Upper digits all have the same length 8 symbols I want to remove the passwords than contain 5 or more digits not necessary consecutive:...
1
vote
3answers
54 views

Nailing down vim regex substitution

I started using Vimwiki to document weekly progress on my projects last year. As the year rolled on, the format of my list of links to weekly wikis changed a bit. At the end of the year I decided to ...
0
votes
3answers
37 views

Match file names with prefix, few digits and a suffix regex

How do I match file names abc_NNN.xyz? here is the directory content [root@ tmp]# ls -ltr total 0 -rw-r--r--. 1 root root 0 Jan 3 00:42 abc_123.xyz -rw-r--r--. 1 root root 0 Jan 3 00:42 abc_234.xyz ...
2
votes
1answer
44 views

Look for multiple line string from bash

I am currently working with Jupyter notebooks. With an IDE I used to be able to look for parts of my code that could be elsewhere, and thus refactor as needed. Suppose I have the following code: ...
3
votes
2answers
49 views

Bash - replace spaces with underscore but replace multiple spaces with one

I use rename to underscore spaces in filenames, simply with: rename "s/ /_/g" * but I encounter the problem that files downloaded from the internet often have multiple spaces. A nasty workaround I ...
2
votes
1answer
50 views

Use regex for file matching, not string matching

I'm trying to figure out how to use grep to search for for a specific string, (for the sake of simplicity) say "9", and I want to search for this, again for simplicity, on all files containing the ...
0
votes
2answers
42 views

awk: Insert line after comments and imports in source file

I have bunch of source files with very usual structure: some comments in header, some (optional) imports, and then source code, e.g.: // // AppDelegate.swift // settings // // Created by Mikhail ...
1
vote
1answer
48 views

How to detect dot (.), underscore(_) and dash(-) in regex [closed]

I need to process information dealing with IP address or folders containing information about an IP host. I need a pattern that can identify (match) IP addresses, whether an actual url, name of ...
1
vote
1answer
36 views

Hex code for '(' in bash regex

I have a strange behaviour in shell. When I try to match '_' in regex with its hex code it works, but not with '('. $ regex1=$'\x5f' $ pattern1='_' $ if [[ $pattern1 =~ $regex1 ]]; then echo yes; ...
1
vote
1answer
72 views

Match ASCII codes in shell regex

I've trouble about matching ASCII codes in regex in my bash script. My payload is : payload='#1243669, start 2018-12-17 16:32:50 CET' My old regex is : regold='(#[^,]+),' My new regex is : regnew='(#...
1
vote
1answer
28 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 ...
0
votes
2answers
56 views

Why regular expression '[a-z][0-9]+$' not work

I use the regular expression to handle the string "abc123". The command below is work and return value "c123" echo abc123 | grep -o [a-z][0-9]*$ But the command below does not work. echo abc123 | ...
1
vote
1answer
42 views

how to find the higher java version on linux machine with bash or shell script

we need to test and compare java versions any suggestion for tricky way how to verify if $version > $New_version ? [root@master tmp]# version=$(java -version 2>&1 | awk -F '"' '/version/ {...
0
votes
1answer
18 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
52 views

How to remove all comments from a javascript file using common Linux command line tools? [closed]

I have a javascript file with deeply needed comments. Javascript uses C style comments: //this is a single line comment And /* this is a multi-line comment */ However, the actual code looks ...
0
votes
1answer
60 views

wget download regex pattern files from remote URL

I want to download all *httpd* RPM file from remote CentOS mirror and I am trying he following command but it doesn't seem to work [root@yum foo]# wget -r --no-parent -A "*httpd*" https://mirrors....
0
votes
0answers
15 views

Text processing - Regex search for string and output unique values [duplicate]

I have a use case where I would like to search the following text for any Windows AD objects in backslash format. Here is a use case to use as an example. My goal is to output the unique results to a ...
1
vote
1answer
53 views

Ask sed to ignore all special characters [duplicate]

I use the following code to delete a line : sed -i "0,/$DELETE_THIS/{/$DELETE_THIS/d;}" file.txt But this code fails if the variable DELETE_THIS contains special characters, like ., /, * and so on......
0
votes
1answer
45 views

Regular expression used in sed not giving the desired result between intervals [duplicate]

I am using the sed command to get the data between 2 dates. I am using regular expression matching the pattern for the dates. The sample data I am using is somewhat like: 192.168.0.123 - - [25/Nov/...
2
votes
1answer
24 views

Filter files by string timestamp in filename

I've got a folder with several thousand files with names like ousjgforuigor-TIMESTAMP.txt The timestamp is a standard Unix timestamp (e.g. 1543932635). Is there an easy way to list only files with a ...
1
vote
2answers
39 views

Postfix: Remove the software name in the email header

I need to remove the software name in the email header. Every time when I send the emails, the postfix server sent emails at the destination the emails headers include the following: by mail.example....
0
votes
0answers
21 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
1answer
48 views

Get lines of file matching a regex

Is there a more compact way to get lines of a file that match a regex than the following? open my $fh, '<', $file or die "Cannot open $file: $!"; while ( my $line = <$fh> ) { next ...
0
votes
2answers
67 views

Grep only numbers, not the alphanumeric entries

I have a list of values like: 1 2 3 4 Ak123 Ak23 Ak147 1Apple 2Apricot 3Mango 4Orange I just want to execute a simple grep command to list me only the numbers. i.e. 1, 2 , 3 and 4. I tried this ...
0
votes
1answer
32 views

AWK print specific fields without specific word

Input: a-0;Password-1010;c-ss;d-fk;h-14;i-jawad;j-dd;Email-1@1.com; a-7990:15:71;b-aa;c-1;Password-2020;h-iOS;Email-2@2.com; Output: 1@1.com,1010 2@2.com,2020 my input file is the same as my ...
0
votes
1answer
47 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
54 views

some sed commands fail when in background

Some sed commands seem to fail when run in background. Minimal example below. One sed command appends append after a block of lines that begin with a star *. The other just substitutes a word. The ...
1
vote
2answers
18 views

How to use sed regex to replace to words related to each other and one character between them

How to use sed regex to replace to words related to each other and one character between them with out change the character and the two words as group like that ahmed#mohamed ahmed$mohamed ...
0
votes
3answers
35 views

how to check if FQDN host-name is with only small letters

we want to check the hostname on machines the rule should be like this: each hostname must be only with small letters each hostname is FQDN we try this hostname=master01.nassa.com [[ $hostname =~ ^...
1
vote
1answer
40 views

perl-rename - What is the difference between /g' and /'?

I want to replace all dashes in all .txt-files with spaces. Fortunately, I ultimately found using perl-rename 's/[-]/ /g' *.txt does what I want. But before that, a few minutes of search and t&...
2
votes
2answers
174 views

How to write regexp literal in match expression?

This question is about the proper way to write regular expression literals in a match expression under bash. In zsh, the match below succeeds, as I expected: % [[ ' 123 ' =~ '^ [0-9]+ $' ]]; echo $? ...
2
votes
4answers
53 views

Compare the numbers in text file, if meets the condition run a shell script

I have a text file (created by a script) which contains only numbers in a single line like "5 17 42 2 87 33". I want to check every number with 50 (example), and if any of those numbers is greater ...
0
votes
1answer
38 views

bash regular expression point “.” character not matching

The string I'm trying to match is an ip address and I've seens quite some examples on the web. However it appears that I'm missing something which may or may not have to do with the differences ...
0
votes
1answer
32 views

sed/awk file data manipulation

I have many text files prepended with digits like this: 12 some text here some text here some text here Or sometimes like this: 123 text here some more not-so-interesting text here some text here ...
1
vote
2answers
52 views

Regex, delete all characters after the last occurrence of “/”

I have a list of pathnames like this in a file: /path/to/directory/one.txt /longer/path/to/some/directory/two.py /path/with spaces/in/it/three.sh I want to delete all characters after the last ...
0
votes
2answers
44 views

Replace same line in file 1 from file 2 with conditon

File 1: 19a9s c9019 5777 File 2: 99a9s 89019 10919 Expected output 19a9s 89019 5777 So in file 1 on line#2 it's start with letter c. which i would like to use it as condition if the line start ...
0
votes
2answers
50 views

Regex for sed/awk command

I would like to change the file content which i specified like below.I want to comment out all the lines which contains ".class" except the class name i provide. @MyClass1.MyClass2(value = { ...
1
vote
2answers
136 views

How can I use a bash variable as a regex argument to gsub() and match()?

I have a script #! /bin/bash awk -v pat="$1" '{ if(match($0, pat)) {print $0} }' "$3" awk -v pat="$1" -v rep="$2" '{gsub(pat, rep); print $0}' "$3" I would like to run it like myscript '\.\.+' ' ' ...