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

learn more… | top users | synonyms (1)

2
votes
2answers
72 views

Replacing matching text after two matching lines

I have a YAML file which includes a stanza looks this: admin::common::passwords: alice: password: '$6$oTQhLvN/4VFJPscD$8LYwUMSFi' bob: password: '$6$JKOtLF0wHeZfIskt$W/M5.ugDS' If the ...
1
vote
2answers
48 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
97 views

Find works fine in command line, but won't work in script

I am trying to write a script on a Debian Jessie host. I am having an issue with trying to run the following command (with a twist) in a script: find ~/* -path ~/FileSniper* \ -prune -o \ -type f \( ...
2
votes
2answers
142 views

Delete row if two patterns are found in the same line

I'd like to delete a line from a text file (input.txt) if two patterns (string1and string2) are found on the same row, using sed. I'm trying: sed -i "/\b\(string1\|string2\)\b/d" input.txt, but ...
1
vote
2answers
41 views

Regex on Postfix using Centos

I have a Centos server running only postfix. I want to filter out mails containing word gratis or grátis or grétis or grâtis. The second letter is the problem. So I used this rejex: ...
2
votes
4answers
49 views

How to append a line that does not start with '<' to the previous line

I have a log which contains XML lines. Sample format below: <head> <body> <line> asdasd</line> </body> </head> I want to scan the log file and ...
1
vote
2answers
31 views

Java comments regex: egrep “(/\*\* | /* | \*/ | \*\*/)” text.txt

I'm trying to extract lines starting or ending a Java comment: What I have is: egrep "(/** | /* | */ | **/)" text.txt I noticed that this works for all lines (such as /* comment */) except ...
0
votes
2answers
66 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...
2
votes
1answer
75 views

sed regex for capture group between delimeters

I have a two line file that I'm trying to get some info out of for a bash script using sed. # File Comment PrefixForInformation {information to be captured} I need to get the information between ...
0
votes
0answers
13 views

UnionFS with filtering to determine default save location

I'm wanting to set up a UnionFS mount which will save all files/directories matching a certain regexp (or similar pattern-matching system) to one location and all other files/directories to another ...
1
vote
4answers
101 views

Grep for a number in line

Can someone help me to get the below two outputs? Input /usr/IBM/WebSphere/7.0/UpdateInstaller/java/jre/bin/java -Declipse.security -Dwas.status.socket=48101 ...
2
votes
1answer
86 views

String digit regex replacement

I'm struggling a bit with this replacement regex, I could not understand why it is behaving this way. What I want to do is to replace all numeric digits after the last /: str="aa/a0b0/42" echo ...
2
votes
3answers
52 views

Recursively delete files with 'WIDTHxLENGTH' in the name in a directory

I have a directory that has subdirectories, and I want to delete images named like thumbnail-name_WIDTHxLENGTH.{jpg,png}, where WIDTH and LENGTH are both decimal integers, like box-image-150x150.jpg ...
3
votes
2answers
94 views

How to search for the word stored in the hold space with sed?

This is a sed-specific question; I am well aware it could be done with other tools but I am working on expanding my knowledge of sed. How can I use sed to globally quote (actually backtick) a word ...
0
votes
1answer
24 views

how can I target filenames with 2 digits with the rename tool?

I am trying rename files in a directory which have a 2 digit number - i.e. any and all numbers from 10 to 99. I want to prepend a 0 so that for example 23 becomes 023, so that files like this ...
2
votes
5answers
574 views

Replace characters in user part of email address

I have a list that looks like this: user-name@domain.example user.name@domain.example user_name@domain.example ... I would like to replace any occurence of a dot in the username part. So that: ...
1
vote
2answers
147 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 ...
3
votes
4answers
193 views

Match-zero-or-more operator in shell globbing

I'm stuck in a quite trivial problem here: how can I make the * symbol in bash mean zero or more, like it does in tools such as sed? For example, ak* should match any file whose name consists ...
1
vote
3answers
177 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 ...
2
votes
1answer
146 views

How do I combine grep with multiple arguments and different output switches

I want to grep with multiple arguments where i want to show lines in the order they appear in my source file before one argument and lines after the other argument , i e combine: grep -A5 onestring ...
0
votes
0answers
94 views

Need help with a regular expression with calibre

I'm actually in trouble about some regex in order to import books properly with calibre. Hopefully someone more experimented than me will have time to help... My book's names (entries) are in this ...
4
votes
2answers
330 views

difference between [] and \(\) in Basic Regular Expression

Consider: $ echo '<H1>heading</H1>' | grep '<H\(1\|3\|2\)>.*</H\1>' $ <H1>heading</H1> and $ echo '<H1>heading</H3>' | grep ...
2
votes
1answer
56 views

Running grep for a string with non-rendering characters

So I have a log.txt files which I can search in Notepad++ on Windows, however due to the sheer number of them, I'd like to be able to run grep on them. However, the data is formatted with ...
4
votes
1answer
47 views

What REs can I use with =~ operator

The man page for bash has this to say about the =~ operator: An additional binary operator, =~, is available, with the same precedence as == and !=. When it is used, the string to the right of the ...
0
votes
0answers
14 views

AWK searching for numeric patterns in a string [duplicate]

I'm trying to remove any occurrence of six-digit numbers occurring in my data. for instance: "This is test data 765648.txt" would become "this is test data.txt" and "This example 457623 has ...
0
votes
2answers
39 views

Find the position of repeated character “&”

How can determine the position of “&” in the column number 5 to substring the value 2 or substring value 3 by awk functions column1|column2|column3|column4|variable1:value1 & ...
0
votes
1answer
138 views

SED find and replace element in filename with incremental values

A sample filename is Sample-0.0.1-SNAPSHOT.jar (result of a maven build in jenkins). My goal is to run a shell script that executes on failure and what that script does it adds incremental numbers to ...
1
vote
1answer
56 views

sed - simple regular expression replacement not replacing

I'm trying to use sed to remove any subdomain prefix from a list of hostnames, but it's not replacing anything when I use a regular expression. Here's the simplified example that's not working: echo ...
3
votes
2answers
68 views

Remove all but the latest backup file monthwise

I've got a directory, containing lots of weekly generated files with names like db_20130101_foo.tgz db_20130108_foo.tgz db_20130115_foo.tgz ... and so on. Over the years, the disks will get ...
8
votes
3answers
134 views

grab text by pattern with start and end tag in multiple lines [duplicate]

I want to grab multiple lines in a file with a pattern that has a starting and an ending tag in an ungreedy way. For example I have the following input: file.txt START test1 test2 foo END some more ...
1
vote
1answer
144 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
2answers
94 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
0
votes
2answers
53 views

how do i write a regular expression using grep to find lines that start with 'O' or 'o' AND contain 2 consecutive chracters

how do i write a regular expression using grep to find lines that start with 'O' or 'o' AND contain 2 consecutive 'c' characters. grep '^[Oo]c{2}' filename
3
votes
2answers
98 views

Using find -exec how to print name of file in front of each line?

Similar to, but beyond: find . -iname "somepatter*txt" -print -exec cat {} \; How might the file name from each file be printed in front of each line with the results from find?
2
votes
2answers
87 views

Remove specific (known) extension from filename if it's there

I'm not even sure whether grep is meant to be used for regex in one-line data. Googling led me to this lookahead expression that, along with grep, matches any .ext file and returns bare name: ...
1
vote
2answers
71 views

Using a shell variable with grep [closed]

I have a list of tokens in a text file and want to use grep to get the lines from a second text file that contain those tokens, but seem to be having trouble accessing the shell variable with grep: ...
1
vote
1answer
24 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 ...
4
votes
3answers
145 views

egrep regular expression for times over five minutes

I have the following time formats in a text file `1` equals one second. `5|01` equals five minutes and one seconds. `13|01` equals thirteen minutes and one seconds. `21|12|01` equals 21 ...
1
vote
2answers
56 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 ...
4
votes
3answers
225 views

grep regular expression solution (greedy not working)

I have the following text in the data.txt file :MENU1 0. public 1. admin 2. webmail :SYNTAX ! opt1, ... : :ERROR1 Error #1, blah... blah.. blah... Please do ... :ERROR2 Error #2 ... and I want ...
2
votes
2answers
84 views

Cleaning PHP exploits from infected files using sed

Recently my server has been a target for a series php exploit attacks and using ClamAV I was able to identify many infected files. The catch here is that there are legitimate files that are infected ...
0
votes
0answers
45 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
0
votes
1answer
73 views

Match everything after backslash and before space

I have strings similar to the following: *unknown*\*unknown* (8) hello\morning (3) I'm trying to match just morning or *unknown\*. So far I have tried: [^\\]+$ But that matches from backslash ...
10
votes
5answers
1k views

How to print file content only if the first line matches a certain pattern?

I am writing a script, I want to check if the first line of the file matches a certain pattern and if it does then print out the file. How can I achieve this? How do I check for pattern? Is there a ...
-3
votes
1answer
116 views

Regular expression: when every alternate character is a digit

I am trying to write a Linux command using egrep that validates lines whose even character is a number. I am doing it this way: egrep "^(.[0-9])*$" text.txt However, this fails for i) empty ...
0
votes
1answer
26 views

subtract dates from two files for same process

I have initiated 50 processes and in one file "say start_time", I have stored when process was started and in another file "say end_time", I have stored when process finished. files are like below - ...
1
vote
2answers
81 views

how to swap text inside files [duplicate]

Inside my file I need to swap places of all instances of : grep 'search string' and sed '/string of text/,/string of text/{//!d}' In VI I have tried a regex with no luck - it says something ...
0
votes
1answer
18 views

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME.

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
-3
votes
1answer
42 views

Regexp pattern - is it correct and what is its purpose? [closed]

Is this pattern correct? logPattern = ^NAME.log(-\d+)?$ What is the purpose of this?
1
vote
1answer
108 views

Including or in grep pattern

I want to grep a word wrap in single quote or double quote eg. "myWord" 'myWord' I am using grep -rn "\"\|\'myWord\'\|\"" this should allow "myWord" , 'myWord" , "myWord' and 'myWord' , but ...