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

learn more… | top users | synonyms (1)

1
vote
3answers
109 views

regex matching and substring extraction

I have these files, manually created by many different people are coming in. Formatting, although following a certain rule, is not uniform. think of these three lines below ...
1
vote
3answers
131 views

Fast field extraction with grep

The problem I have a 32M lines file with the following format token^Iname^Iurl$ where ^I is the tab escape sequence, and $ is the end-of-line. I need to get the url corresponding to not more than ...
1
vote
2answers
80 views

How can I use the environment variables inside a regular expression in awk?

#!/bin/sh ALTER="1153" NAME="aio" for i in $(ps -eo pid,etime,comm | \ awk -v alt="$ALTER" -v name="$NAME" '$2~/[^0-alt]-/ && $3~/name/{print$1} '); do echo $i done
1
vote
2answers
54 views

Remove last comma within a pattern

If I have the following text within a file (somefile.txt): CREATE TABLE "table_name" ( "id" int(11) unsigned NOT NULL, "some_field" varchar(10), ); CREATE TABLE "another_table" ( "id" ...
1
vote
4answers
184 views

Delete everything before “/” on every line

I am trying to delete certain text that appears before / on every line. I have something like: testing.db.com/7fad416d-f2b3-4259-b98d-2449957a3123 ...
1
vote
1answer
837 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 ...
1
vote
2answers
288 views

Ack regex on filenames

According to this thread: Q: My understanding is that ack uses Perl-derivative regular expressions, is that correct? A: Yes. In fact, ack is written in Perl and just forwards the expressions ...
1
vote
3answers
418 views

Replace a string and replace it with a part of itself

I am cleaning up my data that is stored in text files. Each line starts with a category label followed by the actual data that I want to clean up. There are many text files in different subfolders, so ...
1
vote
3answers
2k views

What does the dot in regex “^[A-Za-z]{2}[1-9]{2}.*” do?

I am very new with regexp. I would like to know the pattern defined by this regexp : ^[A-Za-z]{2}[1-9]{2}.* It starts with 2 alphabetic characters then 2 numeric characters then a . and * which is ...
1
vote
2answers
75 views

use search result in replace statement with vim substitute

I know this is gonna be a stupid question, but I've tried here, google and the official documentation. I've got a file with a whole heap of words of the form 'foo' and i want to change them to ...
1
vote
2answers
321 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
1
vote
4answers
2k views

using simple regex quantifier expression in grep

Does anyone know why ls | xargs -n 1 basename | grep -E '[0-9]{1}' does not only show occurrences of a single digit between 0-9? For example if I have: touch 1 touch 22 touch 333 touch test_file ...
1
vote
2answers
80 views

Grep and regex, Why does the following return only a specific portion?

Why in the following: echo this is a line. | grep -o -E "[a-z]+\." The result is line. and not this is a line.? There is no word boundary or any other restriction on the regex.
1
vote
3answers
772 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
1
vote
1answer
66 views

Regular expressions help

what the different between these two regex expression ? AB\{4\} and (AB)\{4\} for the first expression I think that it repeat B 4 times, then for second expression it repeats AB 4 times. When I ...
1
vote
2answers
334 views

Match a simple Regex

I need to match this: (tt\d{1,10}) in a file with the file ending txt. I have tried grep and ack-grep but without results. ack-grep -G \.txt$ -g "(tt\d{1,10})"
1
vote
2answers
594 views

How to find and replace files contents that match a pattern?

Suppose we have a folder named Project. I would like find each file in the folder that contains the pattern &$ at the function call. For example should replace: AnyFunction(&$arg); with ...
1
vote
2answers
903 views

pattern search and display the last occuring pattern?

I have a log file containing startup and shutdown times for everday. I want to see the last pattern for startup and shutdown (which is located at the end of the file being updated everyday). Also I ...
1
vote
4answers
3k views

Processing control characters

I have a log file which contains a bunch of non visible control characters such as hex \u0003. I would like to replace this using something like SED, but can't get the first part of the regex to ...
1
vote
3answers
113 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
1
vote
3answers
60 views

How to sort blocks of lines with a specific line from the block?

I have a file with the data like this BEGIN hello2 5 world1 END BEGIN hello4 2 world5 END BEGIN hello6 4 END I want to sort the lines in the following manner based on the number inside the block. ...
1
vote
3answers
91 views

How to grep all words starting with digit?

I am wondering how to grep all words starting with digit. So far, I have made this: egrep "^[[:digit:]]" tst But it prints me just a lines starting with digit. Thanks in advance with help.
1
vote
2answers
40 views

Help with regular expression in grep

someone can explain me why this regexp doesn't work in grep? ls -la ./ | grep -E '^d.*\<\..*\>$' In my (wrong) opinion this have to show me the line of the directory with a name that start ...
1
vote
2answers
54 views

How to make + work in sed's regexps on FreeBSD?

Consider the following typescript: $ freebsd-version 10.0-RELEASE-p5 $ echo ' found' | sed -n '/[[:blank:]]\+/p' $ echo ' found' | grep '[[:blank:]]\+' found When I do this on Arch Linux with GNU ...
1
vote
1answer
145 views

Sed replace portions of lines not beginning with http://

I'm getting stuck with sed.. I'm trying to prefix links in an html file with a / when they don't start with http.. I'm aware this is possibly not the best way to go about this but I'm just after a ...
1
vote
3answers
132 views

parse credentials from PHP configuration file

I'd like to write bash script to parse data from a configuration file. I searched for this but without finding something I could modify to suit my needs. Joomla! config file: public $access = ...
1
vote
1answer
92 views

How to use sed to replace keys in a file using a regex?

I would like to modify a file to replace keys, suppose these keys are in the file as: 42NM 52NM 23NO XNNM I would like to replace anything with NM, with the word "Okay". 1 #!bin/bash/ 2 3 if [ ...
1
vote
2answers
64 views

To Regex Pandoc Tables

Minimum Data to regex \documentclass{article} \begin{document} ------------------------------------------------------------- A B C D Header Aligned Aligned ...
1
vote
2answers
1k 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-> ...
1
vote
2answers
193 views

Why does regex with \\$\{ work with egrep, but not with sed?

Given a text like this ./RFF_09 -f${FILE} -c${COND} inside a file, this egrep command will correctly match: egrep './RFF(.*) (.*)-c\\$\{COND\}' file but this sed command will not sed -n ...
1
vote
3answers
203 views

How to express all files/directories at the extra -exec option of `find` command?

I have a task to copy all files from multiple directories with special names to a target directory. So I build this directory to test my command. The test directory tree looks like: . ├── dir1 │   ...
1
vote
2answers
91 views

Why doesn't my regex work in bash “if”? [duplicate]

Here is my code: if [ -f /Applications/xml[0-9].pl ] I also tried with -f =~ and double brackets but none seem to work. I first though that the regex might be faulty but I tried this. echo h1 | ...
1
vote
3answers
1k views

“bad flag in substitute command: '{” while replacing a string with sed from one file to another file

I am trying to replace strings found in File1 with strings in File2 File1 <IMG SRC="/Repository/GetImage.dll?baseHref=Orange/2011/03/27&amp;EntityID=Ad12911&amp;imgExtension=" /> ...
1
vote
1answer
145 views

vim replace search text by manipulated search text

This is a very simplified version of my problem. Suppose I have a text file containing several places the code 20091a or 20092a or 20093a. I'm wishing to surround all this code by the text ...
1
vote
4answers
678 views

Enclose multiple lines in quote Vim

I have blocks of the following form: String that is not supposed to be enclosed in quotes String that is supposed to be enclosed in quotes String that is not supposed to be enclosed in ...
1
vote
2answers
3k views

Regular expression find 3 or 4 numbers

So, I have 50+ words and I have to match the numbers in them. These numbers can be 3 or 4 digit numbers. I think I tried every way there is, but nothing seems to work (I need to remember the number as ...
1
vote
2answers
649 views

Find duplicate file names with specific matching pattern

I have a folder with some files (snippet of the contents of the folder) PAT1.URGRSVP.50.WR786842JOB11632.WRS20140.FILE0005.DAT PAT1.URGRSVP.50.WR786842JOB11643.WRS20140.FILE0003.DAT ...
1
vote
1answer
2k views

How do I join the next line when a line matches a regex for whole document in VI?

As title, for example, I have lines like abcdefg join! abcdef no join abcdefg join! If a line matches regex ^a.+g$ then I would like them to be joined, so it would be: abcdefgjoin! abcdef no join ...
1
vote
1answer
112 views

How to match a literal '*' with sed?

I have this line in my file called test.php 'dbs_password' => 'a8b*cyP0', and want to replace into: 'dbs_password' => 'password-here', So I use this sed command with syntax: $ sed -e ...
1
vote
2answers
434 views

How can I combine grep with file and extra regex

I have a file of strings in each line. For example: AAAAA BBBBB CCCCC etc I want to check each string one by one whether it exists in a series of files in a specific directory. I ...
1
vote
3answers
10k views

Regular Expression for finding double characters in Bash

I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash). Main Question: Is there a simple way to look for sequences ...
1
vote
2answers
4k views

Pattern matching from the input arguments

we're trying to enhance the scripts. Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...
1
vote
2answers
419 views

Match neither regex

I have a Bash script which installs a customised JBoss. The name of the JBoss instance is checked against a regular expression to make sure that the name is valid: if [[ ! $1 =~ $instanceNameRegex ...
1
vote
1answer
21 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
1
vote
1answer
33 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
1
vote
2answers
14 views

bash regex to find and save string from file

I'm a noob, so thanks for your assistance. Need some bash help... My file, hi.html, has many lines of text. I need to hunt down the line that starts with Hello abc123 blah blah blah and then save ...
1
vote
2answers
18 views

using egrep & regex

Suppose I have the following text file called inputFile: hello HELLO Hello World wOrld asdgfsafd abc 123 1 3 5 a b and I want to print out the lines containing only one word(any sequence with ...
1
vote
2answers
93 views

“egrep: empty (sub)expression” when attempting to filter out words from a list

I'm trying to follow this question/answer from Server Fault: In tail -f, how do I filter out stuff that has certain keywords? The following is producing egrep: empty (sub)expression: # Respect ...
1
vote
1answer
81 views

pkill with regex

I have few java processes running like below, java -jar /my/path/to/app/myapp.jar java -jar /my/path/to/app/prodapp.jar java -jar /my/path/to/app/testapp.jar java -jar ...
1
vote
1answer
22 views

Regex quantifiers are not working well with locate

This output is rather self-explanatory: XXXXX@debianvirtualbox:~$ locate -r "^/var/lib/tomcat[0-9]/.*" -l 10 /var/lib/tomcat8/conf /var/lib/tomcat8/lib /var/lib/tomcat8/logs /var/lib/tomcat8/webapps ...