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

learn more… | top users | synonyms (1)

5
votes
3answers
96 views

Replace uppercase to lowercase except first letter of each word in specific line

I want to replace names that I received in uppercase letters only. The names are mixed with other information which should stay as it is. AUTH: at the beginning of the line identifies it as a line ...
1
vote
0answers
16 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 ...
0
votes
3answers
101 views

Shell script to add or replace block of text?

I'm looking for a shell script (Bash) that adds or replaces copyright text at the beginning of the file (for .c and .h files). It should search and add or replace the copyright text block for all the ...
-2
votes
1answer
25 views

Regular expression in unzip files argument not working

I'm trying to view the contents of a zip archive using an extremely simple regular expression. This works: rmorton@Rockette:~$ unzip -l Downloads/WeiDU-Linux-236.zip "*/i386/tolower" "*/i386/weidu" ...
0
votes
2answers
34 views

Regex gone Wrong

I am using a Bash script to use awk to look for this: (0010,0080) The awk will generally look for any numeric value seperated by a comma in between parenthesis. I have done everything I can think of ...
4
votes
2answers
6k views

Grep 'OR' regex problem

I am trying to use grep with a regex to find lines in a file that match 1 of 2 possible strings. Here is my grep: $ grep "^ID.*(ETS|FBS)" my_file.txt The above grep returns no results. However if I ...
1
vote
2answers
25 views

Erasing in stdin all instances of regexes defined in a file

I am after something like a combination of sed 's/pattern//g' and grep -f patternfile.txt. Basically I would like the input stream to be stripped of all instances of the regex patterns defined in ...
1
vote
3answers
164 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 ...
4
votes
2answers
164 views

Print repeating pattern

I have a marathon file from which I want to print the names of the runners, who have made multiple runs. Something like: M, 2:08:58.0, John Lukas, USA, 1997-07-25, Paris, France F, 2:15:04:0, Abebbe ...
1
vote
1answer
46 views

How to find strings using regular expressions in grep

So I have a file list with list of the people in a company. Each line contains Position(a short string), years, name(first and last), salary and nationality(three capital letters). They are divided ...
4
votes
3answers
211 views

“parentheses not balanced” even though I escaped it?

Im trying to run this simple sed command sed '/VALUES\ \([0-9]/d!' It still gives me an error saying "RE error: parentheses not balanced" (yes the quotes are there). What can I do? I mean I could ...
0
votes
3answers
61 views

Strip the file base name, keep the directory part

I have a string which looks something like this dir/subdir/othersubdir/file.txt But it can also look like dir/file.txt or dir/subdir/file.txt Now, I am making a script where $P is the full ...
0
votes
1answer
34 views

combining grep ignore and matches

I would like to grep a file to find all instances of the text fn1 that don't have the word call in front of it and print out four lines before and after the matches (even if the surrounding lines have ...
3
votes
2answers
142 views

Sed: modify every non-first word repetition for every word in text

Can you help me to do something like that using sed? qq ab xyz ab qq aa ab Becomes: qq ab xyz +ab+ +qq+ aa +ab+
2
votes
3answers
462 views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
1
vote
2answers
37 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 | ...
0
votes
2answers
47 views

Bash regex string manipulation bug

I have an issue with bash and its regex match ability that I for now think is a bug in bash but could also be me having missed something obvious. I hope it is the latter. I have made this function in ...
0
votes
2answers
42 views

Regex long list of numbers

What is the command in Linux to find the regular expression e for every number from 37 to 200 included in a list with such numbers?
3
votes
2answers
44 views

Coloring tail output with perl

tail -f logfile.log | perl -pe 's/.*foo*/\e[1;41m$&\e[0m/g' will color all the lines containing the pattern "foo" in the logfile.log file. How can I make use of this in order to highlight ...
2
votes
2answers
123 views

regex - Searching for only character pairs

I have the following data from which I mean to extract only those lines which contain "bb" only. Not "b" or "bbb" or anything else just "bb". abb abbb aabbcc aabab abbbbc Now when I use the ...
0
votes
1answer
52 views

No output from grep -P 'com\K\w+'

I have a source file saved off the internet which has various links I want to pull data from. For example https://blahblah.com/uniquetext I'm using grep -oP 'com\K\w+' source.txt > list.txt ...
2
votes
2answers
411 views

Regular expressions with ExpectJ

I've been used the ExpectJ Java library to automate some jobs on a Linux server, however now I need to automate a job that sends a different text response for each execution. Here is the output: Last ...
1
vote
2answers
166 views

grep pattern exacly matching from file and search only in first column

I have a bigfile like this: denovo1 xxx yyyy oggugu ddddd denovo11 ggg hhhh bbbb gggg denovo22 hhhh yyyy kkkk iiii denovo2 yyyyy rrrr fffff jjjj denovo33 hhh yyy eeeee fffff then my pattern file ...
0
votes
2answers
35 views

How to make my regular expression accept zeroes in the input?

I wrote a regex that accepts numbers between 0 and 999,999,999,999.99. Commas are optional, but, still should accept value not higher than 999999999999.99. I wrote one, but, there are two flaws in it. ...
2
votes
5answers
138 views

Remove backslashes from a text file

I have Input: NISHA =\455 Output: NISHA = 455 I want to remove \ from output. I tried to use command sed "s/[\]//g" P but it is not working and it flags an error: character found ...
1
vote
4answers
159 views

SED command not replacing (working regex)

I'm trying to replace in one of my projects all mysql to mysqli, with their parameters. To do so, I'm searching for all files with mysql in my folder recursively and replacing it with mysqli. Ex: ...
3
votes
3answers
33 views

Parsing Log Files with sed -e. Need to count unique class names

I have a file, let's call it filename.log, in it I have something like this (2014-11-18 14:09:21,766), , xxxxxx.local, EventSystem, DEBUG FtpsFile delay secs is 5 [pool-3-thread-7] (2014-11-18 ...
0
votes
0answers
51 views

how to exclude range of numbers using regular expression

I'm trying to write a regular expression in order to cover all numbers starting with 1809 and excluding some ranges: Ranges needed to be excluded Starting with 1809 and followed by: ...
3
votes
3answers
101 views

Why does my grep expression need to use $'string' to match tab characters?

If you take this code: echo -e '\t\t\tString' | grep '^[\t]*String' the result is blank because it doesn't match, yet this: echo -e '\t\t\tString' | grep $'^[\t]*String' works. I swear that I ...
0
votes
1answer
28 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
1
vote
0answers
22 views

grc: Highlight capture groups only?

Recently I came across grc and I find it really simple. However, I would like to highlight some chunks of regex-matched text. For example, svn status properties conflict highlight I hoped to work: ...
2
votes
4answers
149 views

remove leading string in bash

I try getting this sed command to work. I have a string like rev00000010 and I only want the last number, 10 in that case. I have tried this: TEST='rev00000010' echo "$TEST" | sed ...
2
votes
4answers
3k views

remove white space before delimiter with sed

I have data of the following format that I want to input into LibreOffice calc data | num | num | num | num For some reason Libreoffice does not think the string "3214 " is a number by ...
0
votes
3answers
90 views

Simple way to extract value from HTML

I have a very simple html file with a value inside. Value is 57 in this case. <eta version="1.0"><value uri="/user/var/48/10391/0/0/12528" strValue="57" unit="%" decPlaces="0" ...
13
votes
7answers
3k views

Software for visually building regular expressions?

I frequently need to create regular expressions for use in scripts (mostly when used in sed), however, I find, sometimes the regular expressions get very complicated and difficult for me to understand ...
1
vote
1answer
30 views

Search and remove with regular expression

How do you use regular expression in bash to search any given string and remove occurrence of particular word? This is the expression I've come up with ^([A-Za-z-]+)(-).*(el6.*)$ What I would like ...
1
vote
2answers
51 views

How can I use sed to remove the first paragraph of the file?

So the paragraph is defined by having a empty line at the end. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc et nisi tristique, facilisis orci nec, pellentesque tortor. ...
1
vote
1answer
36 views

perl rename: Prepending something to a set of file names across subdirectories

Although perl's rename tool has become an invaluable companion for my daily work, there are still some quirks that make work more difficult - especially when files are not in current work directory. ...
4
votes
3answers
152 views

Use sed to delete all but a certain pattern

How do I get just the link part in the http-source of a link? I have <a href="http://unix.stackexchange.com/users/20661/">Unix &amp; Linux and would like to get just ...
1
vote
5answers
77 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
-1
votes
1answer
31 views

SMTP log anonymize script

I have a SMTP log with records in the format below: 6,222.3.4.5,3040,100.2.3.4,25,UNKNOWN,0,1,……,9337bc-929a-34c0-29a8-b3a89c834b29 ,protocol,SMTP ,745663746,STATUS-COMPLETE ,VALID ...
0
votes
1answer
40 views

How to escape unbalanced brackets or slash in sed?

I'm trying to use sed, but my pattern contains [] brackets and slashes (/). I've tried quotes, but it doesn't help. How do I escape it? Examples: $ sed -i'.bak' "s/^includes[] =/;includes[] ...
14
votes
10answers
3k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTex, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
4
votes
5answers
133 views

how to use regex in alias?

I want to create the alias for the command "ssh user@10.32.44.225" as 10.32.44.225 alias [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9].[0-9][0-9][0-9]="ssh user@$0" I have created it, but it is ...
0
votes
0answers
16 views

To visualise look-behind in this Regex

I am using Regexr to visualise my regexes now. I need look-behind but Javascript does not support it, example code here. The project code base seems to be dependent Javascript (NodeJS) in Github. I ...
1
vote
1answer
46 views

How to nest global matches with sed?

If I do: sed 's/match/replace/g' I know that sed will substitute replace for every occurrence of match on a line. But what if...? echo "match <please dont match this?>" | sed ...
7
votes
2answers
427 views

In VIM, replace path with slashes without using escape slashes

In vim I want to substitute a long path /a/b/f/g/d/g with another /s/g/w/d/g/r in a text file. Usually I use \/ but there are too many slashes here. Is there an easier way?
1
vote
0answers
29 views

Need .htaccess Rewrite Rule To Remove Trailing <br%20/>

I have links that for some reason have a trailing <br%20/> and I don't know where they are coming from to try and fix them. So I need a general rewrite rule to remove them so the links won't ...
2
votes
2answers
216 views

How can I remove lines matching foo but not matching bar?

Assume I want to remove the 2nd and 3rd, but not the 4th line in the following file (those which match foo but do not match bar), can I easily do this with e.g. sed? text foo some more text even more ...
3
votes
4answers
278 views

Decreasing a number with sed

I extracted the metadata of a PDF in a .txt file using pdftk, and now I am trying to decrease the BookmarkPageNumber value for each bookmark by an integer. The .txt has these lines: BookmarkBegin ...