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

learn more… | top users | synonyms (1)

1
vote
2answers
53 views

How to do operation on individual matches in a full line

I have a Verilog line like this: if (i2_0&!(i2_1)) (posedge i0_0 => (o:1'b1))=(0, 0); How can I convert it to a line like: if (i2_0 == 1'b1 & i2_1 == 1'b0) (posedge i0_0 => (o:1'b1))=(0, 0); ...
1
vote
2answers
24 views

To Regex Pandoc Tables

Minimum Data to regex \documentclass{article} \begin{document} ------------------------------------------------------------- A B C D Header Aligned Aligned ...
1
vote
1answer
50 views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
2
votes
0answers
17 views

Why does find not match repeat / quantifier expressions with emacs regular expressions? [duplicate]

I have a file 'abcd' in my current dir. Using find -regex '\.\/[a-d]\{4\}' gets me no results. While the regex works fine in emacs itself. find, however, does find my file when I add -regextype ...
4
votes
3answers
172 views

RegExp testing with ash shell (BusyBox)

I need to do a RegExp pattern test on a certain bit of user input. This is the pattern I need to test the value against. ^([a-z]{2,3})\-([a-z][a-z]*[0-9]*)\-(\d+)$ An example match would be: ...
0
votes
3answers
30 views

How to match and replace an attribute value inside a tag

I am trying to replace the value of following node using sed command. <KeyValue key="EMPTY_SEARCH_CRITERIA" type="String" value="CS_CODE" comment="Configured empty search criteria."/> I am ...
0
votes
1answer
36 views

grep searching groups

I'm trying to learn to use grep groups, like sed \1\2\3, but have a problem. For example I filtering /etc/services file to separate all ports. What I do: ~$ grep -E '[0-9]{1,5}/(tcp|udp)' ...
0
votes
1answer
31 views

How to replace multiple occurrences of a pattern with sed

I use the following command to remove surrounding spaces between array keys that are strings or integers in PHP files: sed -ri "s/\[ ([0-9]+|(\x27|\x22).*(\x27|\x22)) \]/[\1]/g" file.php I thought I ...
6
votes
1answer
135 views

Why can't I escape the braces “]” in sed?

Question: Why can't I escape the "]"? $ printf "*#$@~\!&*()[]\n" *#~\!&*()[] $ printf "*#$@~\!&*()[]\n" | sed 's/[*#$@~!&*()\[\]]//g' *#~\!&*() $
2
votes
2answers
42 views

Can't get GNU grep 2.12 to handle LF character in regex expression

I've been at it for over an hour, but can't find why it's not working. I'm searching an HTML document for "\nSome text". Simple enough. But he following commands won't work: grep -Po ...
0
votes
1answer
35 views

Use sed to only replace namespace in an element that has a parent element with a given attribute value

I want to replace the namespace in an xml file using sed (I've given up trying to do it from ant, where it is required). The main issue is that that there is a repeating list of elements - not all of ...
2
votes
1answer
18 views

Seeing all regex matches in a file in Bash

I'm in bash and I have a file, I want to find all matches of a regex in it and have them printed. How do I do that? Followup: Assume I want to print only unique matches, i.e. if a match appears ...
2
votes
2answers
95 views

How to escape correctly this word on vim?

I want to substitute this word ${ARRAY1[@]} with $1 on vim substitution command I did :%s:\$\{ARRAY1[\@]\}:\$1:g But give me error about number of repetition,i try also "" but doesn't work How to ...
2
votes
2answers
86 views

Extract substrings from each line. These substrings are in comma separated, “name=value” format

I have lines in a file that are comma separated. There are no column headers, it's mostly comma separated 'name=value' pairs. Here is some test data: ...
7
votes
3answers
136 views

How to use [\w]+ in regular expression in sed?

I am on Windows, but I guess my question is still rightly placed here. C:\Users\User>grep --version GNU grep 2.6.3 C:\Users\User>sed --version GNU sed version 4.2.1 I noticed that the ...
1
vote
2answers
45 views

Delete text from a file using regular expressions

I have lots of text in a file. I want to delete all text that are between symbols === and <!!!>. E.g. Text ===some comments<!!!> lala ===aaa<!!!>" should be Text lala after running ...
0
votes
3answers
41 views

What characters should I escape while modifying a file using sed? [duplicate]

I am using the following sed command(with word boundary): sed "7 s/\<<Filevalue=.*/>\>/<Filevalue="true"/>/" < config.xml And I am getting this error: sed: command garbled: 7 ...
0
votes
3answers
30 views

To grep version number from Wordpress plugin folder

What will be grep regex to extract version number like Version: 3.1.5 * Version: 3.1.5 Will output 3.1.5 But It should not catch likes MIME-Version: 1.0\n Here is my grep command grep ...
1
vote
2answers
107 views

sed: problem while replacing string using wildcard

I am trying to replace a string using the following command: sed -e "s/\<$5\>/$6/g" "$2/$1" > "$4/$3" $5-> "hostname=*" $6-> "hostname=int1" $2/$1-> "source file path" $4/$3-> ...
0
votes
3answers
24 views

To improve this regex about digit separation

Code m/([+-]?\d+\.\d+)[\s\t]+([+-]?\d+\.\d+)/ Data 22.585698 3601.767090 D:\measurements\LabCourse_2015\6\90deg\image0001_23_mT.png 20.051883 3580.268555 ...
0
votes
1answer
23 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
1
vote
1answer
27 views

nginx location regex with proxypass

I am quite new to nginx so excuse me in advance if i am asking something obvious. What i am trying to do is to proxypass to another server a request that comes to my nginx server in the form of: ...
1
vote
1answer
36 views

How to write a regex to look for strings with fixed length with at least one occurrence of a character

I've been doing some reading on regular expressions and thought I had everything covered, until recently. I've had to filter out all strings of length 5 which end with the letter t and contain at ...
0
votes
0answers
28 views

Regex for a non-fixed pattern

I am trying to come up with the right regex (compatible with python) that would match a file that contained sample input as follows: On the third day of Christmas my true love sent to me: three ...
6
votes
4answers
144 views

Extracting subset of lines of a file based on regex for first & last line

I have a large text file and I only want to look at some of the lines. The first line I want matches a regex R, and when the line matches the regex S, I don't care about that line, or any following ...
4
votes
1answer
82 views

How to tell “grep -w” what characters make up “words”?

$ printf 'asf .test. afd\nasaf foo-test asfdads\n' asf .test. afd asaf foo-test asfdads $ printf 'asf .test. afd\nasaf foo-test asfdads\n' | grep -w test asf .test. afd asaf foo-test asfdads ...
13
votes
6answers
387 views

/bin/dash: check whether $1 is a number

What would be the best way to check whether $1 is an integer in /bin/dash ? In bash, I could do: [[ $1 =~ ^([0-9]+)$ ]] But that does not seem to be POSIX compliant and dash does not support that
3
votes
1answer
22 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...
2
votes
1answer
36 views

grep with regular expression

I want to match all the lines that are of the below pattern in a file using grep. Abc::xyz() [18-Feb-15 12:09:16] I came up with below regex with grep , but it is not returning match. Please help ...
4
votes
4answers
302 views

How do I extract parts of a string to variables?

I have a line from some file like this: attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks... I want to extract the 512^3, 16^3, 32^3 and 800 four ...
1
vote
1answer
35 views

sed exception handling of escaped characters

I want to delete anything that follows a % to the end of the line. Using cat /tmp/foo.txt | sed 's/%.*$//' works great with one exception: I want to ignore any escaped percent signs \%. So with ...
2
votes
1answer
48 views

Using fixed strings in regular expressions?

I am writing a bash script which accepts a list of CSV files as arguments and outputs e-mail addresses only found in the first file. To accomplish this, for each record in the first CSV file I look ...
1
vote
1answer
131 views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
2
votes
2answers
39 views

Perl non-greedy regex matching more than it should

I have the following text from which I need to remove some wdiff output. text='Иса Мәсіхтің елшісі Петірден [-(-] осы күнәкар дүниеде [-)-] жат жерлік болып, Понти, Ғалатия, [-Қападоқия, Азия және ...
0
votes
1answer
82 views

Bash detect ascii art [closed]

For bash script, is there a easy way to detect if a text contains ascii art? An example of ascii art:
2
votes
0answers
92 views

Bash regular expression comparison fail for hex byte \x01

Bash regular expression fails to compare correctly for $'\x01' when End-Of-String char $ is used. All other byte values (seem to) compare correctly. Using GNU bash 4.1.5(1). Is this a bug, or is ...
0
votes
1answer
40 views

What is the email matching regex in basic regex for grep?

I created a text file and put some email addresses in it. Then I used grep to find them. Indeed it worked: # pattern="^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-z]{2,}" # grep -E $pattern regexfile but only as ...
0
votes
1answer
43 views

Vim: Count all occurrences (including multiple on the same line) of char or word

I try to count all occurrences of a char or word in a file with Vim. This means multiple occurrences of the same word in the same line should be taken into account as well. This has been discussed in ...
0
votes
1answer
26 views

Interactive less search with wildcards [duplicate]

I'm using less to view a large file and I want to search for a pattern with wildcards — e.g., " x 1??" where ? is any character. Does less support that, and if so how would I do that ...
1
vote
1answer
48 views

Find only in directories n levels deep

I use this command to find and run all istances of wp-cron.php I have for each site I have: find /var/www/ -name 'wp-cron.php' -exec php -q "{}" \; Since my websites tree is: ...
9
votes
3answers
720 views

Strange behaviour of “ls -a | grep ^\.”

I wanted to list the content of a pwd and display only file starting with dot. I tried ls -a | grep ^\. but I cannot figure out why the output contains also the files which do not start with dot. For ...
0
votes
2answers
33 views

Vim: Substitute based on another match in the line

I have rather large files in which I need to substitute NX for N1 but only if the line already contains NX as a pattern. So far I do it manually by first searching for occurrences of NX with: /NX ...
1
vote
3answers
154 views

How to perform grep onto the output of ldd properly ?

# ldd /usr/bin/ffmpeg linux-vdso.so.1 => (0x00007ffffc1fe000) libavfilter.so.0 => not found libpostproc.so.51 => not found libswscale.so.0 => not found ...
5
votes
5answers
371 views

How to replace a word with new line

I have a text file with following data and each row ends with |END|. T|somthing|something|END|T|something2|something2|END| I am tryig to replace |END| with \n new line with sed. sed ...
3
votes
5answers
323 views

How to grep the n-th substring between given delimiters?

Let's say we have a string and its delimiter is ?: Leslie Cheung April 1 ? Elvis August 16 ? Leonard Nimoy February 27 I know how to grep the first substring between delimiters: echo $above_string ...
1
vote
1answer
53 views

Pattern matching and removal of that pattern using sed

I have 2 files with the following names: File 1: RvA_X-IRB-bil-CA101-0+010000-20150327212332-055582-P File 2: RvA_X-IRB-bil-CA101-1+020000-20150327212332-055582-P I am using this command to match ...
0
votes
3answers
48 views

grep log lines of a specific id request

So, I have the following log sample: 2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1 2015-03-30 ...
1
vote
2answers
50 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
0
votes
4answers
45 views

AWK print regex pattern

I am trying to print a regex pattern for the following piece of mail log. In particular I am trying to get the ID between the square brackets (see the second line for reference). Mar 29 03:48:13 ...
1
vote
2answers
102 views

regular expression to extract information in shell script

I would to grep certain parts of some shell command output in the shell script: $ uname -r >> 3.14.37-1-lts Where I just need the 3.14.37. And also for the shell script variable VERSION that ...