Questions tagged [regular-expression]

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

Filter by
Sorted by
Tagged with
2
votes
2answers
34 views

How to refer to a regex group in awk regex?

How can I refer to a regex group in awk regex? For example, if I have a regex group (\w), how can I refer to it later in the same regex like (\w)\1? Does awk support this feature? Below example doesn'...
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
45 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
33 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 ...
4
votes
1answer
42 views

Rename files and directories with French characters

I use the following command on Ubuntu with rename (installed with sudo apt-get rename) to rename all files which have the given characters in regex: find . -execdir rename 's/[^A-Za-z0-9_.@+,#!?:&...
1
vote
2answers
31 views

sed + delete all words that not contain string before the “dot string”

I castrated the following sed syntax in order to remove from file any host that not contain linux/LINUX sed -i '/linux\|LINUX/!d' file example linux01.moon.com solaris.moon.com UNIX.foot.com it ...
1
vote
1answer
17 views

how to apply multiply regex-find & replace commands on one text file? [closed]

I have one textfile (written in markdown) to which I want to apply a bunch of regex in order to find and replace certain structures. Can you give me a hint how to approach this issue? Can I write a ...
0
votes
0answers
31 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
2answers
42 views

Character class regex confusion

I'm trying to abbreviate a regex in a grep. I need to match exactly six spaces followed by an alpha character. This works: grep "^\s\s\s\s\s\s[[:alpha:]]" <filename> This does not: grep "^[[:...
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
1answer
29 views

Solaris - Get directory names that starts with a pattern

I'm working on Sun Solaris 10 OS, which is grep -o is not allowed with modern systems. I have the below list of directory I'm trying to fetch any directory starts with DATA[0-9] only DATA34016 ...
0
votes
2answers
74 views

And operation and case insensitivity in awk regular expression?

I'm trying to match filenames that contain two text patterns but the matching process should ignore case. Neither of the following regular expressions work: Setting the awk variable 'IGNORECASE' to a ...
1
vote
4answers
54 views

How can I use sed to insert some text after a multiline match?

I have a file sample.txt like this: lots of text lots of text #nvram = [ # these # could # be, # anything #] lots of text lots of text and I want to add some text "foobar" to get this: ...
1
vote
2answers
34 views

How to grep multiple lines?

Grep understands this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "clipper-coin" But not this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "{*clipper-coin*}" The output I ...
0
votes
2answers
52 views

Delete line only if previous line has tag - sed ? or easier?

I'm facing a rather newbie problem and caught my ears around it :( I have a file with xml tags and I want that when I find: </ac:image> </a> the </ac:image> one followed by ...
1
vote
1answer
28 views

Help with regex

Okay, this is almost a pure duplicate ... with one little piece of information that I just don't understand. The original question is: Sed Explanation: sed '/./,$!d' file And relates to the ...
6
votes
3answers
100 views

Replace MAC address with UUID

I am looking for a way to mask the client MAC address every time it appears in a logfile before using the logfile to present data to a customer (GDPR rules). I can identify the MAC string using regex,...
1
vote
1answer
34 views

Extended Regex clarification

This is an example from the book Linux Command Line If I am trying to match (555) 123-4567 or 555 123-4567 - the following extended regex can be used. ^\(?[0-9][0-9][0-9]\)? [0-9][0-9][0-9]-[0-9][...
0
votes
2answers
28 views

Specifically lower case email-addresses only

Example (random) text: StackOverflow@icloud.com:Portuguesa-Span103 StackOverflow@gmail.com-Snip1031 Stackoverflow@icloud.com:Sanchismo103 Desired output: stackoverflow@icloud.com:Portuguesa-Span103 ...
1
vote
1answer
24 views

Replace *\n.*\n= using sed

Given text in file is as follows: oldValue =null* persistedObjectId ="STRAN-2019-10420"* persistedObjectVersion =0* propertyName ="Status"* uri ="/oms/salesOrder/saveSalesOrder" How do i ...
0
votes
1answer
16 views

How to search for all tabs between two quotation marks with grep / egrep

I'm looking for all tabs between two quotation marks with grep / egrep in a bash. I tried grep -r . -e "\".*\t.*\"" grep -r . -e "\".*\\t.*\"" grep -r . -e "\".*\\\\t.*\"" grep -r . -e '\".*\t.*\"' ...
2
votes
3answers
44 views

Regex to match error between 2 lines that contain ##

I have the follwing log file.. that contains some_error_message. If some_error_message occurs between two lines that contain ## (echoed as "##"), we consider it as error occured in remote ftp/sftp ...
4
votes
2answers
373 views

grep and grep -f differences

I have a file with the following 3 lines: file.txt aaa| bbb| ccc| and another file with one line: regex.txt ^aaa\| $grep ^aaa\| file.txt yields: aaa| $grep -f regex.txt file.txt yields: aaa| ...
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
1answer
31 views

Regex for footnotes in Markdown

I'm preparing a document in markdown for print and as an EPUB file. I want to remove footnotes for word definitions for the EPUB file. The foonotes I want to remove are in the format [mean-X] where X ...
3
votes
1answer
321 views

Why is regex [0-9]{0,2} not greedy in sed?

echo '123980925sriten34=ienat' | sed -e 's/^.*\?\([1-9][0-9]\{0,2\}\+\)\([%=+-]\).*/ \1 \2 /' is giving the result: 4 = I am expecting: 34 = What am I not understanding? (Oh and I even added ...
1
vote
4answers
83 views

sed delete lines containing exact number of a specific character

I want to delete lines containing exactly N instances of a character. In this case, character /. I'd prefer to use program sed.
1
vote
1answer
20 views

Regex is not matched using sed

I want to find a regex which contains the word Sat followed by one or more commas. I used this: sed -e 's/Sat,+/Sat/ig' myfile.txt > output.txt But it has no effect despite the fact that the file ...
2
votes
1answer
46 views

match curly braces {} with sed

I want to remove \includegraphics from .tex files in order to get a list of the filenames as illustrated in the following example. I want to remove x and y and get I something {\includegraphics[width=...
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 ...
1
vote
2answers
62 views

Replace a string pattern by a sequence using sed

I want to replace a string in a text file with a sequence of numbers such as 1 2 3 4 5 6 7 preferably using sed. Here is what I have tried (without the search string) and seems to work: for i in {1.....
0
votes
1answer
54 views

bash + grep only the time stamp from output

we want to capture the time from the output and not the time from the command sshpass expected output Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 but from ...
0
votes
1answer
51 views

Filtering a .txt file using a regular expression and a second file

I have a file.txt (it does not have the same number of columns for each row): e.g. 1 21:10 21:23 2 1:94 1:100 1:123 3 14:1 14:60 14:23 I have another file (file2.txt) that contains 4 columns (...
1
vote
2answers
23 views

Swap words within email address

I have the following "incorrect" email addresses that needs to be rearranged: com@user1234.google com@user4321.yahoo com@user5555.outlook I tried the following, but didn't work: sed -r 's/(^[A-Za-...
0
votes
6answers
95 views

Simplest way to extract a portion of a string?

I've got a file (bigfile.txt), one of the columns looks like this NW_017095471.1 Gnomon mRNA 108321 109565 . + . ID=rna34;Parent=gene27;Dbxref=GeneID:108565285,Genbank:XM_017925071.1;...
0
votes
1answer
101 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=...
6
votes
3answers
504 views

Extract string from each line of a file

I have a file where each line contains a sentence where one word is found between the character > and <. For example: Martin went shopping at >Wallmart< and lost his wallet French food >...
0
votes
2answers
29 views

How to delete everything before the occurrence of a regex pattern per line in a bash variable

I've got a bash variable containing several lines of text, which includes IP addresses, and I need to remove 'everything' before the last IP address occurrence in the same line. This: 43.12.40.53 ...
0
votes
1answer
68 views

Perl regex matching apostrophe fails

I'm trying to write a Perl script to transform several sripts into a canonical form. I expected the script #!/usr/bin/perl -W use File::Spec; use Getopt::Long 2.3203 qw(:config auto_help auto_version)...
0
votes
2answers
22 views

Remove trailing char if condition matches

Let's say I have a file with many URLs: http://foo.com/abc_(Programming_Language) http://example.com/test) I'd like to remove the trailing ) for each line in which there is no opening ( using sed ...
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
0answers
20 views

Replacing RegEx Capture Group Content Using sed or perl [duplicate]

The exiting index, has been name as index=_np and index=_pr on each stanzas. Base on that, the script has modify the exiting index name to index=secure_np and index=secure_pr Below is the example. ...
0
votes
3answers
73 views

How to grep multi lines

I want to find all files, who contains two lines: abc and def. For example, xxx 111abc yyy 222def333 This file should be caught by grep because it contains abc and def. What should I do? I've tried ...
0
votes
0answers
28 views

Replace RegEx Capture Group Content Using sed or perl [duplicate]

Modify or remove any exiting index name to index=secure_np. DIR eg.(_EZAC_pr_linux_w1/local/inputs.conf) I try this but not able to modify the index name to index=secure_np perl -...
0
votes
3answers
61 views

Can regex edit a particular word in a particular line by going to the line using some other word from that line

Consider the following file: Name Id department some 13 IT hey 12 IT what I actually want to do is read a name from the user and edit its particular id or department. I am trying ...
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@' ...
1
vote
1answer
37 views

Odd behavior (bug?) of sed when using $

I've got a problem and I am not sure whether this is a bug or if this is supposed to happen when using $ for addressing lines. Basically, I have the following command: sed -e '$s/test/tset/g' ...
1
vote
1answer
28 views

sed -E for groups

This $echo '| foo | bar | baz |' | sed 's@^|[^|]*|\([^|]*\)|.*@\1@' return bar as desired. How would I do the same with opt -E? https://www.gnu.org/software/sed/manual/html_node/Extended-regexps....
0
votes
1answer
26 views

Extract pattern in perl

Is it possible to have just one regex which can extract the pattern "Mango-1.whatever.." in any of these 3 conditions (i.e. $dummy). I keep printing everything after this pattern. If I use comma in ...
1
vote
4answers
48 views

How do I extract with sed numeric characters between two characters?

I have a random text, followed by a colon (:) and a space, then a numeric result, then another space and other arbitrary text; for example: text: 30 (5 new) I need to extract only the number 30; for ...