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.

0
votes
0answers
10 views

Change hostname in tnsnames.ora file

I'm trying to write a script to update just the hostname in the tnsnames.ora file. I'm needing the entry to work case insensitive. For example ${DBNAME} is lowercase database name and in my tnsnames....
1
vote
0answers
13 views

Find + regex: looking for a file name with multiple extensions, but missing the basic filename.jpg

I'm both a regex & SE Unix and Linux newbie, so I hope I'm doing everything right. I'm looking for files that have a name inside of the filename, and could have different extensions. I based my ...
2
votes
2answers
36 views

How to print all the matched string using awk?

My inputs are something like: ["https://www.tesing.com/watch/80239279"], ["https://www.testing.com/watch/80240715?source=35"], ["https://www.testing.com/watch/80242619?trackId=254015180&tctx=0%...
0
votes
1answer
28 views

grep all strings that start with a certain sub string, and finish with the first quotation mark

I'm new to regex and I'm trying to extract all the unique occurrences of each competition. So it should return FA Cup but only once no matter how many FA Cup games are in the file <Date="2014-02-...
0
votes
3answers
73 views

perl regex - How to match foobar that does not begin with (\s*//\s*)

Basically I want to find foobar on uncommented lines like: // foobar # do not match me foobar # match me otherfoobar # do not match me To match the commented lines I use this: ^(\s*//...
1
vote
0answers
21 views

Regex matching comma-separated list of values, trailing comma not allowed

I want to match: aaa aaa,bbb aaa,bbb,ccc But not a list with a trailing comma. My current regex: (\w{3},?)+ also matches lists with trailing commas (aaa,bbb,). I was thinking I could also do: (\w{...
0
votes
2answers
58 views

Linux command to delete this

I want to delete this kind a pattern in my text file [-.(D_)-]. I did with sed and awk but no results. basically i want to delete anything that comes between [- & -] along with these characters ...
2
votes
1answer
38 views

How does find -name work?

I can't for the life of me figure out how find with the test -name works. I run find / -name *in and returns a bunch of results: /sbin /sbin/sulogin /dev/stdin to name a few. It's as if it ...
0
votes
1answer
14 views

Sed regex: difference between -E and BRE (Sed & Awk 101 hacks)

Currently I am self learning awk and sed. I found the online book Sed & Awk 101 hacks which I found very good so far. Nevertheless, I came across I haven't continue for a few days because I can't ...
0
votes
0answers
34 views

Storing a grep outcome into a variable [duplicate]

I've recently begun working with Bash and I was trying to do the following: Format the output of uptime Whenever you input uptime into bash you get something along the lines of: 20:30:54 up 43 min,...
0
votes
0answers
16 views

regular expression for replacing group content using sed or perl

Have files in multiple directories that needs to match and parse each stanza and modify the existing index name into andindex=secure_pr. Also i run the script to locate the inputs file in each ...
0
votes
1answer
25 views

Change command to find any text

I have this line of command to find and remove the string: text_to_remove(SOME_VALUE). find . -type f -name "*php" -exec sed -i 's/text_to_remove(SOME_VALUE)//' {} \+ It works fine, but problem is ...
1
vote
2answers
26 views

Format Latex [option]package pairs into \usepackage[option]{package}

I currently have a set of default LaTeX packages I use frequently formatted as follows: package1 [options]package2 [options]package3 package4 ... I would like to be able to convert this to standard ...
-1
votes
1answer
39 views

Replacing with sed expression [closed]

I'm trying to get a value such as "909,999" With this (the example is replacing it with nothing): sed 's/["][0-9]+[,][0-9]+["]//g' But it's not working.
0
votes
1answer
22 views

Trying to parse a string in BASH for [ - _ ]

I have a BASH script that allows a user to specify a jobname. Right now we except everything. We feed this jobname into another executable that can only accept the following formats: job_name, ...
1
vote
1answer
37 views

How to grep characters with their unicode value?

I have the Unicode character ᚠ, represented by its Unicode code point 16A0, in a text file (the text file is encoded(?) as utf-8). When I do grep '\u16A0' test.txt I get no result. How do I grep ...
0
votes
1answer
14 views

sed: Change a variable-length numerical value for an indeterminate string

The string I need to modify in a hardware driver .conf file is as follows: options rsi_sdio dev_oper_mode=13 Looks simple enough, but the developers are happy to change this string which will break ...
0
votes
0answers
37 views

RegEx for replacing capturing group content using sed

Have inputs.conf files in multiple directories that needs to match and parse each stanza and modify the existing index name into index=secure_np and index=secure_pr. Also i run the script to locate ...
0
votes
1answer
28 views

Use sed to append data BEFORE a closing double quote encasing a Path

I need to append the path /opt/dell/dcc of an application outside of the default path statement in /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/...
1
vote
2answers
41 views

regex for a timestamp HH:MM:SS?

In a file named result, containing this: <span class=timestamp><b>15:31:00</b></span> How to grep for the timestamp? Here are some tries and their output: > grep "[0..9]*...
2
votes
2answers
35 views

Regex to check arguments of command

I want to use grep to check if a command called cmd that was ran, contains the word name as an argument. (I know about about !* in Bash, I don't want to use it). Let's say I have the command in a ...
0
votes
1answer
17 views

Looping through files and extracting value in filename. Script not working

Why do I get a "Permission denied" error with the following script: #!/bin/sh if [ -z $1 ]; then echo "no argument given" exit 1 fi for i in /sys/class/rc/rc*; do if [ -e "$i/device/...
1
vote
2answers
88 views

RegEx for replacing capture group content using sed [closed]

Have inputs.conf files in multiple directories that needs to match and parse each stanza and modify the index= to index=secure. This are files type in inputs.conf and also do run the script to locate ...
0
votes
3answers
33 views

Find portion of text in a line, then add it to another part of the same line

I have this: Issue #12345: some more text here https://some.domain/some/path I would like to find the 12345 bit (which is dynamic - so will need to be via a regex), and then add it to the end of the ...
2
votes
1answer
46 views

Bash: Regex for comparing file path

I want to check if an input string matches whitelisted file paths, then only I want to perform some operation. I am doing something like this path1="mydir/**" path2="mydir/testing" [ [ "$path2" =~ "...
4
votes
3answers
172 views

grep exact match two parts of a string

How do I use grep command to get part of string as below? String: orange:"orange", red:"apple", purple:"grape", yellow:"banana", green:"watermelon" red:"strawberries", yellow:"lemon" What I want: ...
0
votes
0answers
23 views

Bash-Perl Make Substitution and Return array (string & number of replacements/substitutions)

I have this code that makes substitutions in a file segment. The code should be left mostly unharmed except for this problem. I need to return back to bash, the number of replacements made by perl ...
0
votes
2answers
44 views

AWK Split Variable

I have the following sequence in a file: AA MUi MUi-j MUi-N ABk ABk-l ABk-N MBk(i) MBk-l(i) MBk-l(i-j) MBk-l(i-N) MBk-N(i-j) MBk-N(i-N) I want to split it in small pieces: The first two chars will ...
0
votes
2answers
43 views

Perl Negative Lookbehind with variable length bypass maybe?

I have this simple code perl -we 'my $file= " # parameter=10 # parameter=10 # parameter=10 parameter=10 parameter=10 "; $file=~ s/((?<!# ))\s*parameter\s*=.*/parameter=replaced/g; ...
-2
votes
3answers
48 views

Perl multiline match for 'something' which starts without '#\s'

UPDATE: The REAL answer to this MULTILINE question was given here by Stephane https://unix.stackexchange.com/a/521560/354415 Alternatively go line by line with perl by Terdon below: https://unix....
2
votes
2answers
60 views

SED regex match EOF and replace/insert

I use the following to successfully find my ANCHOR (regex pattern) and replace it with my param-value inside a file (filepath). sed -i $"/$ANCHOR/i \\$PARAMVALSEDINS" "$FILEPATH" What I need is for ...
5
votes
1answer
118 views

bash regexp matching fails in [[ ]]

I would like to check whether a user is in a certain group via [[ "$(getent group groupname)" =~ \busername\b ]] but this does not work (bash 5.0.3) although the following works: getent group ...
1
vote
2answers
35 views

sed: -e expression #1, char 35: unterminated `s' command

I have a text file with a line like this: SET @@GLOBAL.GTID_PURGED='abae51b1-e1dc-11e8-bfd0-5665b72f6318:1-12559259'; Using sed, I would like to remove that line. I have it partially working in that ...
1
vote
1answer
25 views

Complex regex sed replacement not working but not throwing errors

I am working in CentOS 7 trying to do find / sed one liners to fix a ton of files. Specifically two in a row: First, to add "ignoreOlderThan = 14d" immediately after every [monitor://...] (working) ...
0
votes
2answers
39 views

bash + regular expression + capture java version [closed]

how to capture the jdk1.8.0_112 under /usr/jdk64 /usr/jdk64/jdk1.8.0_112/ while jdk1.8.0_112 is example and could be any other version as jdk1.7.0_112 jdk3.8.2_112 jdk1.8.0_117 jdk1.2.0_112 jdk2....
-2
votes
1answer
69 views

Bash Script general questions [closed]

The first part of what i am mucking around with simply creates a folder entitled command_manuals that contain text file copies of all the commands available at the bash shell, the filenames which are ...
0
votes
1answer
41 views

Grep: Find 3 consecutive char and then follow another char or end of the line

I want to find 3 consecutive characters and then another character or the end of the line. I tried this: egrep '(.)\1{2}' file but I need less results.
-1
votes
1answer
56 views

How do I exclude pre tags from HTML minification using sed?

I am trying to minify HTML using sed My problem: I don't want to minify anything inside <pre> tags, but can't make it work.. Here is what I am using: sed ':a;N;$!ba;s@>\s*<@><@g' $...
0
votes
0answers
80 views

build regexp that does not depend on the order of input data

In my script I'm dumping some out some data and grep with regular expression rules, which assume that the data come in certain order. However I've found that the order of data may vary. So instead of:...
0
votes
1answer
101 views

Advantage of elasticsearch over grep when trying to search keyword in logs files [closed]

I know elasticsearch is good for full text search but when it comes to analyze logs, say nginx logs what is the advantage of using it over grep (with tail, awk, etc.) ? Quite of often I dig through ...
0
votes
0answers
48 views

How can I find in a log a specific timestamp [duplicate]

This is something I really need on a daily basis and it's really hard sometimes I need to get logs from a specific date time from a log file. This is an example of the file INFO | jvm 1 | main ...
0
votes
3answers
37 views

Sed not outputting matches from regex to file

I have a file (data.txt) which contains strings like this: [?1h= => ["AD070517", "AD070518", : ESCESCOOBB "AD070809", "NE0000013", "NE0000014", : ESCESC[[66~~ "LG100085-097", "LG100085-098", ] ...
-1
votes
4answers
163 views

How to represent greater than or equal 3600 in regex

I wrote this regex to match numbers greater than or equal 3600. This is my attempt. However, I am not sure if it is complete: grep -P '36[0-9]+[0-9]+[0-9]*' test.txt I mean positive decimal integer ...
0
votes
1answer
17 views

How to express beginning and end of line in sed

I want to use sed to replace every '} that comes at the end of the line to "}. I wrote: sed -i -e "s/'}$/\"}$/g" But this replaces it to: "}$. What is wrong? How can I use regex in my sed to express ...
1
vote
2answers
15 views

Use multiple expressions in grep consumer

I have these bash functions filter_history(){ grep -v '^cd[^ ]|^ls[^ ]' } get_clean_bash_history(){ cat "$HOME/.bash_history" | filter_history } I am trying to get the bash history but filter ...
2
votes
1answer
96 views

Replace all items that are not belong to characters and numbers by ' '

I want to replace all symbols like '.','-','/' and so on by ' ' I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work and for sed 's/[,;\.\-\/()_]/ /g' example.txt, I found that I cannot ...
0
votes
1answer
35 views

Using Sed in a for loop with a regular expression

I am trying to modify a json file using a for loop to loop over a list of sample names and use sed to fix those sample names. Right now a subset of the input file is; "WA82671", "WA8267-...
1
vote
3answers
86 views

Why does `^[ ]{0,}` not work with linux grep?

This is my sample text. grep w, grep ^w and grep '^[ ]w' are working just fine. [user@linux ~]$ grep w text.txt whitespace 0 whitespace 1 whitespace 2 [user@linux ~]$ [user@linux ~]$ grep ^w text....
1
vote
3answers
55 views

sed command using regular expressions to replace the major minor and release number

I am using Sed to replace the major, minor and release number in version. In my case: version=10.2.0.1 (version=major.minor.release.buildnumber) I don't want to change buildnumber in this ...
0
votes
4answers
48 views

how to capture IP address from info

by the following api we can get the info about master1/2 machines curl -sH "X-Requested-By: ambari" -u "admin"":""admin" -i http://192.23.39.2:8080/api/v1/hosts?fields=Hosts/host_name,Hosts/ip | ...