Questions tagged [regular-expression]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
26 views

How to search for the functions that call specific function in a codebase?

I want to search for patterns in a code similar to this: function foo() { bar(); } Closest I could get was grep -l '^[ \t]*function foo' | xargs grep -l bar and then checking those files ...
0
votes
0answers
17 views

Remove Exact Strings From a File [duplicate]

How do I remove exact strings using sed, tr or awk {98406c4acbf0f57b3ccbc923a6d507f422d9bd8656398f53433e}HTTP/1.0 200 OK What I want to remove is HTTP/1.0 200 OK I tried to do sed but there is a ...
-1
votes
1answer
55 views

Negating bash regular expression [closed]

I am using the following pattern matching condition to detect an error when the variable hn is not a valid numeric integer. ! [[ "$hn" =~ ^[[:digit:]]+$ ]] && errcode=13 But I get ...
0
votes
2answers
32 views

Extract function string before function name with regex

I want a regex that would search for something like: package_name.some_function_name.foo() that would be part of a line and would and extract the some_function_namebut it should be able to work ...
1
vote
1answer
50 views

Converting regular expressions to bash patterns

I have the following regular expressions and want to convert them to bash patterns. itg='^[-+]?[0-9]*$' fxp='^[-+]?[0-9]*[.,]?[0-9]+$' flp='^[-+]?[0-9]*[.,]?[0-9]+([eE][-+]?[0-9]+)?$' I am trying to ...
0
votes
5answers
114 views

Search and replace lines AFTER a regex match using "sed"

This kind of feels like it would be easier in awk, but I'm curious if sed can do it. Here is my input: line 1 line 2 line 3 line 1 line 2 line 3 line 1 line 2 line 3 I'd like to write an in-place ...
1
vote
1answer
35 views

How to remove every pattern match and write it in new file

So i have a long string that have no blanks and i want to remove every time the pattern match. This is how the string looks like: bdy11<entryunit="phoenix"><name>costperdps</...
0
votes
1answer
46 views

Remove and add a character at the beginning of the specified line in a dynamic file

I need to change a specific line of a file; first I will add a char and after some time I will remove that char. Adding a char to a specific line has been asked and answered in this question and works ...
1
vote
1answer
65 views

grep -v does not return complement of grep

I want to filter a file for lines starting with a space. I use the following command: grep -v "^ " < input > input_no_starting_space To double check my results, I run the following: ...
0
votes
2answers
48 views

Grep anything in between two words as long as it's less than specified number of characters?

I'm trying to use something like the pattern "John.*Smith" but instead of matching anything in between John and Smith I'd like to match anything between the words as long as it's of X ...
1
vote
2answers
64 views

regex lookbehind ignore quotes

I have the below string in my file and I want to extract the word after -s, i.e yesterday without quotes : -t -w -g london -s 'yesterday' -e 'yesterday' -f 100000" Required output yesterday ...
0
votes
1answer
33 views

find all file extension recursively from directory and copy all extension files to single directory [duplicate]

I have directory with sub-dir where it has multiple extensions file. I would like to copy all ext files to single directory "scan". Tried running following cmd but doesnt work out: find . -...
3
votes
2answers
154 views

Display grep output with line breaks inside a if statement in a bash script

I want to validate a text file with a script. The file to validate is: FDFHDK JKL 1545665 152 HDKFHDK UHG YRYRUBH DFG 867HDKE WER Valid lines must match the regex '[A-Z]{7}+[[:space:]]+[A-Z]{3}'. If ...
2
votes
2answers
177 views

Tarring-gzipping only hidden directories (or files + directories)

Based on this, to tar all hidden files in the current directory one can use ls -A | egrep '^\.' | tar cvf ./test.tar -T - However, how can one tar only all hidden directories or all hidden directories ...
6
votes
4answers
337 views

Replacing counter in a filename for all files in a directory

After importing several 1000 Files from a camera onto a hard drive I realized, that the counter, used in the process of renaming the file - does not start from 0. This leads to file structure like ...
0
votes
1answer
52 views

Syntax highlighting combinations of strings and comments in nano

I was wondering if anyone could tell me if it possible to configure syntax highlighting in .nanorc so that in the following text ... Dim s$ = "foo ' bar" ' bar "foo" ... the ...
-1
votes
2answers
85 views

What expressions would match the pattern (^[0-9]..[a-zA-Z ]+$) in grep command? Linux bash

Im trying to understand what expressions exactly the regular expression (^[0-9]..[a-zA-Z ]+$) detects in grep command (linux terminal) I know that if I'd write the following command: grep ^[0-9]..[a-...
2
votes
2answers
87 views

Is it possible to remove specific repeated character of a list using regex?

I have a list of one column that contain ~ 100 lines, in which some lines are repeated, and my purpose is to get rid of a specific duplicate lines and leave only one copy, while the other lines kept ...
0
votes
0answers
5 views

MariaDB: sanitizing data before INSERT, keeping raw data AND extract excerpt to another column

Objective: Receive syslog data from Kiwi Syslog, in same query insert both the raw message to column rawmsg AND excerpt source and destination info from raw message to columns source and destination. ...
0
votes
0answers
18 views

Extract coverage out of jacoco test report index.html

I have an index.html file generated by jacoco and would like to print out the total coverage. So it would be printing out '81' or '81%' in the below example. I think it would be fine to match the ...
0
votes
1answer
39 views

bash replacing text in string with wildcard sed/ regnex

I am wondering if this is possible, I want to mass replace a text in various files, this is not a problem. What i cannot figure out, or even if its possible is to replace the text in a specific manner....
2
votes
3answers
511 views

Find: Use regex to get all files with specific directory name in path, but without another specific directory name in path

I'm trying to use find to return all file names that have a specific directory in their path, but don't have another specific directory anywhere in the file path. Something like: myRegex= <regex>...
0
votes
1answer
34 views

Extract unique subdomains from input file

I have a .txt file with 2 million lines containing URLs of the same domain, I need to extract only unique subdomains of this list... The problem is when I use the command below, the output return the ...
1
vote
4answers
59 views

SED and REGEX for EXIF renaming

I was unable to comment on this old post, How can I rename photos, given the EXIF data? but it had a comment that seemed exactly what I needed so I started a new post, I hope not bad form. I get what ...
0
votes
3answers
77 views

Grep for consecutive words with capital letters

I am trying to find two consecutive words that start with capital letters. Example Input: x Yyy Zzz xx y Output: Yyy Zzz Right now I'm able to find all the capital letters cat txtfile.txt | grep -o '\&...
0
votes
4answers
78 views

Combine multiple greps with regex

I have this file: 10 replies Big Horse 123sdf562 replies 1354654 Fat Cat 2 replies White Horse Big Cat Little Dog 5 replies 725vgfvjgh123 Black Horse Brown Cow 8798jgjh I want to extract lines that ...
3
votes
2answers
323 views

How to rename multiple files by changing one component of the file name?

I found lots of questions about how to rename multiple files using the command line. However I am not able to solve my specific issue which is renaming this file name: ...
0
votes
0answers
27 views

Pcre2grep multiline regular expression

I'm trying to create a regular expression to match the first html of a text file with this content: garbage garbage §<html class="test1"> <div>test</div></html>§ ...
4
votes
1answer
73 views

grep a range of characters (decimal encoding)

I have a list of accepted characters: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI These characters can be translated in the ASCII decimal range 33-73 The implementation I'd like would ...
0
votes
2answers
23 views

what wrong with this regex or is debuggex reliable?

I am doing a simple regex test on the below site but it says no match. pattern = aaaa and search string is fhaaaaaaachoeore (some random string). But the below site says - no match. Where is the ...
2
votes
1answer
60 views

Regex: What is the use of positive lookahead at the beginning of regex?

To some extent I understand positive lookahead. X(?=Y), it means "look for X, but match only if followed by Y" But in the below regex - I don't understand the significance of positive ...
3
votes
2answers
540 views

Find returns same path twice, but truncated

I am running this find command: find $HOME * -depth -type d -iname *bowtie* | grep "bowtie*-*1[^2]" My expected out put is: /home/user/Documents/scripts/bowtie1.3.0-linux-x86_64 /home/user/...
0
votes
2answers
24 views

how to perform multi substitution with sed on a block of text?

I have text file, and in it has a block that has pattern like below: # cat file Jit .... enabled=false Jit ..shoes.. From=2021-01-01 Jit ..gloves.. From=2021-01-01 so I want to change all of these ...
8
votes
7answers
867 views

Regex to match on a single instance of a character

I have this thing that I maintain at work, and it has a pretty arcane DSL that it uses. And the tooling for it is not great. To deal with the poor tooling, I've written some scripts to try to find ...
-1
votes
1answer
59 views

Question on using sed, filtering data

Here is a sample text file: store: xxx Delete: xxx Expires: Sat, 30 Oct 02021 13:01:57 +0100 store: xxx Delete: xxx Expires: Sat, 30 Oct 02021 13:01:57 +0100 store: abc store: sdf Expires: Sat, 30 Oct ...
2
votes
4answers
1k views

Bash Regex - string should not start and end with a dot

I have a script that takes a string input from users. I am looking to check that the string input should have exactly 2 dots. The relevance is only to the dots. The string should not start and end ...
0
votes
1answer
34 views

Delete text from files using regex with sed

I'm attempting to use sed to remove some lines from json files. As you can probably tell, I'm very much an amateur but think I have the regex correct. However sed throws various errors including ...
0
votes
0answers
13 views

In `less`, how to get search patterns to match ignoring any colors/highlighting/ansi-raw-stuff? (like the default when looking at a man page)

eg, in the man page for less itself, there's a bit like "less does", with the word "less" in green and the word "does" in default formatting, but nevertheless, when I hit ...
0
votes
1answer
47 views

Why doesn't this one-line sed command work as I thought it should?

Running curl -s 'https://www.idealista.com/inmueble/94238881/' \ -H 'authority: www.idealista.com' \ -H 'cache-control: max-age=0' \ -H 'upgrade-insecure-requests: 1' \ -H 'user-agent: Mozilla/...
1
vote
2answers
64 views

How to grep for hex pattern w/ wildcards?

I'm trying to find the offset of a hex pattern in a file. This works for one specific value: $ grep -obUaP -m1 "\x00\x50\x53\x46\x01\x01\x00\x00\x34\x01\x00\x00" file.bin 3088:PSF4 However,...
1
vote
2answers
52 views

Why does "grep -w" match words followed by hyphen/minus ("-")?

I need to ask you about using grep command in a Bash script in Debian. I have got for example file with these lines: /fruit-/apple.txt /fruit-/banana.txt /fruit-/samples /vegetables-/carrot.txt /...
6
votes
8answers
999 views

Use awk to delete everything after the ","

I have a variable, var, that contains: XXXX YY ZZZZZ\n aaa,bbb,ccc All I want is aaa in the second line. I tried: out=$(echo "$var" | awk 'NR==2{sub(",.*","")}' ) but I ...
0
votes
4answers
157 views

How to extract a portion of an XML tag value in a Bash script

I have a XML file like this (A.xml) : <?xml version="1.0"?> <RunParameters xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
0
votes
3answers
50 views

How can I grep for a block of text that contains certain words across several lines? And how can I do that piped from tail -f?

I want to tail a log file and print ONLY blocks of text that match the regex pattern .*\n.*\nABC(.*\n){1-6}XYZ. In case my regex is wrong already, I want to match this example: TIMESTAMP HERE LOG ...
2
votes
2answers
60 views

Search with line numbers in GNU Ed

I have recently begun learning ed, however I've come to the point where I need to search for text. My first attempt was ed's / command, which will show occurrences, but doesn't include line numbers. ...
0
votes
0answers
10 views

How to escape special characters in MATE Search Tool regex?

MATE Search Tool has an option "Contains the text" where text is always treated as a regex. The problem is I don't know how to escape special symbols there. For example, when searching for ...
0
votes
2answers
60 views

Use a modifier with find command's regex?

I'm trying to use the find command's regex to match newlines using the dot character. This usually is accomplished via the s modifier; however, different regex engines have different formats and I ...
0
votes
4answers
93 views

How to extract value between parentheses where before there is a specific string with AWK

Im able to capture all values between parentheses with awk expression 'NR>1{print $1}' RS='(' FS=')' But im struggling to match one in specific, where i do not want to match by line number but by ...
-2
votes
3answers
50 views

removing dollar sign + matching curly braces multiple times in one line

Original line in file: alarm_name = "${var.environment}-${var.deployment}-${var.service_name}-elb-healthyhosts" Want this line without ${}, ${}, ${}: alarm_name = "var.environment-var....
1
vote
2answers
49 views

Grep regular expressions stopped working for me

Sorry if the question is a bit out of place but I've just started learning Linux 2 days and I don't really have any knowledge to get around the problem myself. I was trying out the grep command using ...

1
2 3 4 5
50