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

learn more… | top users | synonyms (1)

2
votes
2answers
127 views

In-place substitution for lines matching some pattern in a given set of files

Following on from my previous question: Remove slashes/parent paths from filenames inside CSS and Javascript content I arrived at the following command which replaces any filenames in these ...
2
votes
2answers
393 views

lookbehind and using it with grep in Vi?

Trying to get into Vi (not Vim), after learning Vim. Vim has a lookabehind like /\(Not this\)\@<!$, how to do it in Vi? If I want to search recurvively down directory in Vim, I could do :vimgrep ...
2
votes
3answers
455 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 ...
2
votes
2answers
409 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
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
123 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
183 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
155 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
111 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
140 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
883 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
67 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
415 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
929 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
87 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
966 views

rsync exclude based on file size?

Is it possible to exclude files in rsync over a certain size (e.g. over 250 MB)? And what if I also want to exclude hidden files? How would I exclude all hidden files or directories (those that ...
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
615 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
744 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
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 ...
1
vote
2answers
156 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
98 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
469 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
52 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
216 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
245 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
237 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
480 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
553 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
36 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
2answers
49 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
235 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
116 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
803 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
303 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
305 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
172 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 ...