Tagged Questions

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

learn more… | top users | synonyms (1)

1
vote
2answers
74 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
30 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. ...
1
vote
5answers
108 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 ...
3
votes
3answers
22 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 ...
1
vote
4answers
119 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: ...
0
votes
0answers
44 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
87 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
22 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
15 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
135 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 ...
0
votes
3answers
74 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" ...
1
vote
1answer
29 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
39 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
27 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
139 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
votes
1answer
24 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 ...
1
vote
5answers
64 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 ...
0
votes
1answer
24 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[] ...
4
votes
5answers
104 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 ...
8
votes
2answers
416 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
1answer
32 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 ...
1
vote
0answers
24 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
211 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
267 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 ...
1
vote
3answers
66 views

Remove patterns from string using bash

I'm trying to remove some patterns from a file input string (parsing file line by line). Here is a sample string: 1: (10/17 12:49:31.175) - CONSTANT ID1 - CONSTANT ID2: RAW DATA OUT > ...
1
vote
1answer
55 views

Regex for contains at least one instance of STRINGA and no instances of STRINGB

What regex will match: contains at least one instance of "1221", and no instances of "7474" i.e. matches "7777 1221 4543" but does not match "7777 1221 7474 4543" I suspect I have to use negative ...
10
votes
4answers
446 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
1
vote
2answers
65 views

What does this regex mean? <!--.*?-->

What does this regex do? <!--.*?-->
-1
votes
1answer
100 views

Regular expression to mask credit card digits in a file

What is the most simplest way to mask all numbers but the last 4 digits of a credit card number in a file using sed. Using egrep with the following regular expression we can find numbers of Visa, ...
0
votes
0answers
29 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...
1
vote
3answers
150 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=" /> ...
2
votes
4answers
85 views

replace several comma out side one or more sets of curly braces and exception that in one or more sets of curly braces

In the text file I have multi records. Every record has multi column with comma separated, some column have one sets of curly brace and other have more than one curly brace. I need: If a comma is ...
0
votes
2answers
47 views

Regex to grep filler followed by signed float

I want to extract the last column from lines that look like: 880.952 NAV_Y uSimMarine -146.17516 The number isn't always negative, and isn't a fixed length (i.e. doesn't ...
2
votes
2answers
26 views

Match from current line until a line that doesn't match a pattern

I really tried searching but could not find anything (it's hard to know what exactly to search for). I know how to do this with sed: print from current line until the line that matches SOMETHING: ...
1
vote
1answer
71 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
0
votes
2answers
46 views

To match only innermost environment by Regex

I want to match the innermost environment of begin{question} and its corresponding end{question}. Example data \section{Takayasu arteritis} \begin{question} {You get a patient. What do you notice ...
2
votes
1answer
99 views

To write this Pseudocode with Regex

I am doing a Makefile which I run regularly by Crontab every day at 0230 crontab -e; 30 2 * * * /bin/thePseudocode Python-like Pseudocode directories = ["Cardiology", "Rheumatology", "Surgery"] ...
0
votes
3answers
83 views

Bash Combine Replacement and Sub String Extraction in One Step

For a string in this format: ./my-site.sub.domain.com I would like to remove the .,-, and /, and trim the remainder to 16 characters: mysitesubdomainc I've done this ...
4
votes
4answers
76 views

Replace using vim - Replace a pattern […] by a string

I have a file containing lines in below e.g. format - [foo@host.com, bar@host.com], Payment processed - 23499, params = {'invoice':3243} I only want the account numbers i.e. 23499. It's a number. ...
2
votes
2answers
46 views

What is the regex to validate Linux users?

When adding a new user, how is the string validated? I suppose there is a regular expression. What is that regular expression?
0
votes
3answers
59 views

Shell pattern matching vs. regular expressions occurence [duplicate]

I am relatively new to Unix, and I stumbled across one curiosity. Some shell constructs like case or find, employ pattern matching, but it is not quite regex. Other commands, like ed, sed, vi, and ...
2
votes
2answers
85 views

Find characters in the file

I need to find lines in the text file that have at least one x and at least two ys. I tried the following: grep -E "x.*y{2}" file.txt This method did not work. Is there another way to do it?
2
votes
3answers
342 views

grep to find words with all vowels

Using grep -E and regular expressions I need to find words containing all of a group of characters in no particular order. For instance a word containing all vowels (aeiou) however the vowels can ...
1
vote
1answer
104 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 ...
2
votes
3answers
186 views

Yum regular expression or wildcard search?

Fedora documentation says: 5.2. Advanced Searches If you do not know the name of the package, use the search or provides options. Alternatively, use wild cards or regular expressions with ...
12
votes
3answers
2k views

Why does [a-z] asterisk match numbers?

I have 3 directories at current path. $ls a_0db_data a_clean_0db_data a_clean_data $ls a_*_data a_0db_data: a_clean_0db_data: a_clean_data: $ls a_[a-z]*_data a_clean_0db_data: a_clean_data: I ...
3
votes
3answers
143 views

Replacing a pattern in line preceding another pattern of interest

I have a log file with many instances of statements as shown below: 14 Aug 19 16:30:11.506: <DATA> |POS|IDLE|1|01131844090|5950|$hostIp|$size |$data 20 Aug 19 16:30:12.439: <DATA> ...
3
votes
3answers
606 views

Replacing string in all files found by grep. Can't get it to work

I'm trying to do what title says. So I find all needed files with grep: grep --include=\*.{php,ini,conf,sh} -ril -P "'([\d\w\-\_\.]+)(@domain.com)'" '/var/www_data/somepath/' Now I assume it's ...
3
votes
0answers
36 views

file(1) and magic(5) : prioritizing a result

My question follows that one: file(1) and magic(5) : describing other formats . I want to describe a FASTA sequence ( http://en.wikipedia.org/wiki/FASTA_format) It could be a DNA sequence (with only ...