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

learn more… | top users | synonyms (1)

1
vote
5answers
6k views

(Mac Terminal) sed to parse JSON … what am I doing wrong?

In Mac Terminal, I'm trying to parse the "name" out of this JSON response: {"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12 ...
1
vote
5answers
121 views

Extract one occurrence of a pattern from file

I have large file containing logs similar to one shown below. I would like to find all transactions(TR#) that were affected with the error. I need to extract one occurrence of each TR# ID. How could ...
1
vote
3answers
178 views

Check some property for every line of a file

I have several (427 to be precise) text files with a million lines each containing 31 numbers separated be spaces (possible double spaces). However there might be some data corruption and there may be ...
1
vote
4answers
130 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: ...
1
vote
2answers
105 views

How can I reformat tabular data using AWK?

I have a file contain following output. ora.abc.db 1 ONLINE ONLINE serverA Open 2 ONLINE ONLINE serverB Open ora.xyz.db 1 ...
1
vote
2answers
139 views

Why `rename` behaves differently whenever I use full path instead current path?

Ok, I'm answering a question where the OP have several repositories in Ubuntu that might be causing a problem installing unrelated software. I recommend disabling the PPA's using a single liner rename ...
1
vote
3answers
766 views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I ...
1
vote
2answers
65 views

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

What does this regex do? <!--.*?-->
1
vote
3answers
56 views

Stuck in separating chars into strings in my approach. Found a working approach but can not understand it

I am trying to figure out how to break a string to be on character per line. I.e ahebhaaa to be: a h e b h a a a I tried: $ echo ahebhaaa | sed 's/\(.\)\(.\)/\1\n\2/g' I.e. my ...
1
vote
3answers
3k views

Print lines where first field has only four characters using regex in awk?

John Goldenrod:(916) 348-4278:250:100:175 Chet Main:(510) 548-5258:50:95:135 Tom Savage:(408) 926-3456:250:168:200 Elizabeth Stachelin:(916) 440-1763:175:75:300 output should contain the lines ...
1
vote
3answers
408 views

grep equivalent of the kwrite regex [A-Z][A-Z]+

So, it took me ages, but I finally learned to think in terms of regular expressions, thanks to using them in kwrite. But I still don't know how to translate that knowledge to grep. I love my grep, ...
1
vote
1answer
1k views

Difficulty making a regular expression to find at least 2 occurrences of a character in a file

I have a file containing random codes. Each code has ten characters in it, and I am trying to grep codes in the file that have at least 2 occurrences of a character. I am doing this: grep DD* ...
1
vote
2answers
5k views

Using grep to match only a match group in a regular expression?

I need to set my keyboard layout with setxkbmap before launching Wine games, as I use Dvorak for typing and this breaks every game's controls. What I'd like to do is simply write a script that grabs ...
1
vote
4answers
3k views

Match multiple regular expressions from a single file using awk

I'm trying to parse a HTML file using shell scripting. There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=. Using grep "name=\|age=\|class=\|marks=" ...
1
vote
3answers
869 views

Trying to remove all ids from an HTML file with grep

I'm trying to remove all id=" "s from an .html file but I'm not sure where I am going wrong. I tried using regular expressions but all I am getting is the .html file rendering in my Ubuntu terminal. ...
1
vote
2answers
2k views

Regular expression problem(s) in Bash: [^negate] doesn't seem to work

When I execute ls /directory | grep '[^term]' in Bash I get a regular listing, as if the grep command is ignored somehow. I tried the same thing with egrep, I tried to use it with double and single ...
1
vote
3answers
83 views

Find and change certain LaTeX coding in vim, using regular expressions?

How can I change the following LaTeX coding: \cite{1,3-7,9} to \cite{1,3,4,5,6,7,9} in vim? I would prefer to use regular expressions.
1
vote
2answers
1k views

Differing outputs of the commands “ls .*” and “ls *.”

The command ls .* when run gives as output the following : All the files in the current directory starting with a . (hidden files) All the files in the hidden directories present in the ...
1
vote
2answers
67 views

Pattern repetition and regexp

Take the pattern [UGLER]* Can the string UUG match against it? I mean to say, is repetition allowed?
1
vote
3answers
2k views

grep for an alphanumeric strings of any length with a colon on each side

How would you grep for an alphanumeric strings of 1 to 50 characters (ideally, any length would work too) with a colon on each side – a typical result would be all the lines containing the string ...
1
vote
1answer
1k views

Using grep command and backreferencing

This is a pretty basic question, but I can't get my head around it. I'm learning Linux and one of the questions i've been given is; *The word sentimentalment includes the same three characters ...
1
vote
2answers
607 views

Weird zsh grep -P behaviour

I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is ...
1
vote
1answer
731 views

What does this egrep command do?

What does this egrep command do? egrep '[^A-M][0-9]+' /etc/passwd So far I think it searches for any file in /etc/passwd that starts with A-M and includes the number(s) 0-9. Is that right?
1
vote
2answers
106 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 ...
1
vote
2answers
92 views

Lazy regex using Bash

I'm trying to match just the text contained within the HTML tags using Bash's built-in regex function: string='<span class="circle"> </span>foo</span></span>' regex='<span ...
1
vote
3answers
414 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
51 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
213 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
2answers
76 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
2answers
236 views

Regex and piped commands with sed

I'm finding really hard to use sed command, plus I can't seem to find well written tutorials. Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
1
vote
1answer
60 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
234 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
475 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
3answers
3k views

sed pattern matching

I recently asked someone at work about how to take the output of ipcs -qa and make it space delimited, so I can parse it/store it in the database for monitoring. He gave me this: ipcs -qa | sed 's/ [ ...
1
vote
2answers
541 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 pattern for startup and shutdown(which is located at the end of the file being updated everyday). ...
1
vote
4answers
2k 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
2answers
40 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
3answers
170 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
105 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
536 views

Simple sed replacement of tabs mysteriously failing

This ought to be really simple, but for some reason it is not working: sed -i.bak -E 's/\t/ /' file.txt Instead of replacing tab characters, it's replacing t characters. I've tried every ...
1
vote
4answers
276 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
261 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
1answer
149 views

Why isn't sed using the extended regex mode by default?

I am using sed. I was using a regex that was correct as far as I could see but sed did not do anything. Turns out that I was using \s+ which sed can not understand (?) and when I switched to [ ]+ it ...
1
vote
2answers
358 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
4answers
3k views

Regular expression in Bash to validate IP-address

In my Python script i have a regular expression for searching IP-addresses like 0.0.0.0-255.255.255.255 in a file, it looks like this: ...
1
vote
1answer
66 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
1k views

sed : Ignore line starting whitespace for match

I want to replace the default listening port of httpd to 9090. I can edit the line in httpd.conf file using below sed -i "/^Listen/c\Listen 9090" /etc/httpd/conf/httpd.conf But the line Listen 80 ...
1
vote
2answers
290 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
4answers
545 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
3answers
564 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 "* ...