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

learn more… | top users | synonyms (1)

1
vote
2answers
153 views

How to filter content between specific keywords using grep?

I got a bunch of files, and I want to find out the content between two tags st and et. if I use grep "st.*et" files, I will get these two tags involved in the result. Such as st Hello world! et. But I ...
1
vote
5answers
3k views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the ...
1
vote
2answers
205 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
59 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
2k 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
1answer
2k 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 (e....
1
vote
3answers
889 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
2k 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
7k 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
1answer
362 views

Substring extraction with expr

I was working on extraction of sub-string from the beginning & at the end of the string. I experimented with and with out ".*" $expr "ab1cd1efgfedcbaAAAA" : ".*\(1[a-l]*\)" # Result: 1efgfedcba ...
1
vote
2answers
116 views

how to replace a sed expression (change and print only matched line) with a perl expression?

I am trying to move to perl (from sed). But how can I replace this sed expression with perl in a similarly short way? sed -n '/patternmatch/s%stuff%changed%p' file I need to search for a pattern, ...
1
vote
3answers
83 views

Match beginning of a line with something there?

I want to match the beginning of lines where the line contains something. Command in Perl/Sed 's/^.?/\section{}/g' but the problem here is that it replaces also the first character of sentences. ...
1
vote
3answers
406 views

How to perform grep onto the output of ldd properly ?

# ldd /usr/bin/ffmpeg linux-vdso.so.1 => (0x00007ffffc1fe000) libavfilter.so.0 => not found libpostproc.so.51 => not found libswscale.so.0 => not found libavdevice.so....
1
vote
2answers
585 views

regular expression to extract information in shell script

I would to grep certain parts of some shell command output in the shell script: $ uname -r >> 3.14.37-1-lts Where I just need the 3.14.37. And also for the shell script variable VERSION that ...
1
vote
2answers
1k 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
7answers
73 views

Rename files add dashes after fourth and sixth characters

I have some files such as: 20150716_something-here 20150716_something-heretoo 20150716_something-hereaswell They need to be renamed as 2015-07-16_something-here 2015-07-16_something-heretoo 2015-...
1
vote
2answers
62 views

Why does perl regex find pattern \\label\{.*?\} but not \\ref.*?\} or \\autoref\{.*?\} in TeX Files?

I am using perl to parse many multilingual text files. I need to change the text between two patterns: Desired Changes For example, the English original version looks like this: \label{whatever} \...
1
vote
1answer
56 views

What does a backslash represent when searching for decimals

I want to understand what the backslash represents in this command. grep "\.900983" table I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
1
vote
3answers
44 views

How to grep a heading in a manpage containing control characters

I have a manpage, and I want to find something in a specific section. Grep is having a hard time, and I figured out the issue was headings have control characters in them, e.g. SEE ALSO is really: ...
1
vote
1answer
76 views

grep -E regex syntax changed?

A lot of documentation I've read says that the following command should match lines where x appears at least 3 times in a row but no more than 4 times in a row: grep -E {x}\{3,4} E.g. http://www....
1
vote
2answers
273 views

how to replace a sed/perl expression (change and print only matched line) with a python expression?

I have asked this question to learn how perl could replace sed. Now I want to know how the following commands (which do the same thing) would look like for python: sed -n '/patternmatch/s%stuff%...
1
vote
3answers
1k 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" scaleFactor="...
1
vote
2answers
296 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
182 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 mysite="./my-site.sub.domain....
1
vote
4answers
109 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
81 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
4answers
3k 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
1answer
2k 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
3answers
5k views

How to print only the first match with grep

I'm trying to grep username: users | grep "^\b\w*\b" -P How can I get it to only show the first match with grep?
1
vote
2answers
909 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
3answers
9k 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
1answer
1k 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
5answers
53 views

How can I use the rename command to fix these file names?

I'm trying to change files that look like 01 Track name.mp3 into 01 - Track name.mp3 So far my futile attempts were rename '0. ' '$&- ' *.mp3 rename 's/0. /$&- /' *.mp3 rename '/0. /' '/$&...
1
vote
1answer
86 views

Pattern matching [duplicate]

I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression. I have the following script: #!/usr/bin/env bash # cookbook filename: ...
1
vote
1answer
76 views

regular expression : with a variable

arrFormat=( jpg jpeg bmp tiff png ) varExtension="jpg" for elem in "${arrFormat[@]}" do   echo "${elem}"   # do something on $elem # done #for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do ...
1
vote
2answers
33 views

How extract under linux some capturing groups using command line in a php/preg fashion?

Given in linux environment exists lot of packages for manipulating strings (grep, awk, sed, ...), I would like a software to extract a capturing group in a php/preg like syntax. Maybe the most close ...
1
vote
3answers
41 views

How do I replace this pattern with a newline inside it? [duplicate]

If I have a text file with this content: someline <!--\ file first read on 2015/01/11 And I want to delete <!--\ and everything until what comes after "on", how do I do it? The ...
1
vote
3answers
400 views

regex matching and substring extraction

I have these files, manually created by many different people are coming in. Formatting, although following a certain rule, is not uniform. think of these three lines below "...
1
vote
3answers
217 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 ...
1
vote
2answers
123 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
1
vote
2answers
60 views

Remove last comma within a pattern

If I have the following text within a file (somefile.txt): CREATE TABLE "table_name" ( "id" int(11) unsigned NOT NULL, "some_field" varchar(10), ); CREATE TABLE "another_table" ( "id" int(...
1
vote
4answers
257 views

Delete everything before “/” on every line

I am trying to delete certain text that appears before / on every line. I have something like: testing.db.com/7fad416d-f2b3-4259-b98d-2449957a3123 testing.db.com/8a8589bf-49e3-4cd7-af15-...
1
vote
1answer
1k views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
1
vote
2answers
399 views

Ack regex on filenames

According to this thread: Q: My understanding is that ack uses Perl-derivative regular expressions, is that correct? A: Yes. In fact, ack is written in Perl and just forwards the expressions ...
1
vote
3answers
507 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
3answers
2k 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
78 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
350 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`/" input....
1
vote
2answers
80 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
3answers
813 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 "* ...