Regex (or regexp) is known as regular expression matching of patterns, strings or characters in, for example, a large text file. Questions should be tagged as such whatever the programming language involved and the tag can also apply to command-line or graphical programs that have regex plugins or ...

learn more… | top users | synonyms

14
votes
3answers
3k views

apt-get remove with wildcard removed way more than expected. why?

Last night I was trying to burn CDs. Being annoyed with k3b and choosing to use brasero instead, I went to remove k3b. I typed in: sudo apt-get remove k3b I hit tab twice and saw that I had both ...
12
votes
5answers
6k views

Recommendation for Regex editor?

I asked for recommendations for Regex editors on stackoverflow a while ago. Following is one of the replies: What is "good" depends on what is most useful to you. For me, though, these are ...
9
votes
2answers
5k views

Pattern based, batch file rename in terminal

I need to rename the following: file_001_loremipsum.png file_002_dolor.png file_003_sit.png file_004_amet.png file_105_randomness.png into upl_loremipsum.png upl_dolor.png upl_sit.png upl_amet.png ...
6
votes
5answers
4k views

Text editor capable of running complex Regular Expressions?

I want to find a text editor capable of running and mainly storing regular expressions for later re-use. It should also be able to run them across multiple files. I know I can get all that with grep, ...
6
votes
2answers
10k views

Install Regex plugin for Gedit

I am using Ubuntu 12.04.I want to install Regex Search and Replace plugin for Gedit.So can some one please tell me where can I get it and install it.Any help and suggestions will be highly ...
5
votes
4answers
5k views

How to search for all the files starting with the name “ABC” in a directory?

I need to search for files starting with some particular name. There can be multiple files starting with a particular pattern and I want to list all such files present in the directory.
5
votes
1answer
11k views

How to find a folder on my server with a certain name?

I have a directory somewhere on my server wth the name "exampledocs". I tried to find it's location using: ls -d */ | grep -E 'exampledocs' and find * -regextype posix-extended \-regex ...
5
votes
1answer
156 views

How to rename the set of files with pattern

I have files which has name as following: P50_FR_8_q2_scrolls.csv Here the value 50 and 8 needs renaming & The results should be something like: P21_FR_3_q2_scrolls.csv I tired few ...
4
votes
3answers
276 views

Replace text inside quotes in vim

I have a large sql file and I would like to rename the table name from `feedback` to `comments` but I don't want to replace the word feedback in case any row has that text so I was trying to select it ...
4
votes
3answers
324 views

bash escaping and find command

I trying to remove boring \-escaping from this command: find . \( -name '*.mp3' -o -name '*.jpg' \) -print by wrapping it in single quotes: find . '( -name *.mp3 -o -name *.jpg )' -print ...
4
votes
4answers
362 views

How to find all patterns between two characters?

I'm trying to find all patterns between a pair of double quotes. Let say I have a file with contents look like as following: first matched is "One". the second is here"Two " and here are in second ...
4
votes
2answers
938 views

regex search works with `grep -E` but not with bash script?

I use the same regex with grep and it gives me a match but when doing it in a bash script, it return no match. Test String(part of the file testregex.txt): <a ...
4
votes
2answers
207 views

Using Regex Breaking a text on the last digit using linux tools like sed, or awk

I have the following list that I want to break on the digit. For example: From: 103Ru 103mRh 104 1041 To: 103 Ru 103 mRh 104 1041 I would like to use Regx with sed or maybe awk in order to ...
4
votes
2answers
5k views

Questions about using Regex Search & Replace in gedit

I am trying to use Regex Search & Replace plugin of gedit. I want to search a digit that repeats 2 or 3 times, so I thought the regex was [0-9]\{2,3\} But it doesn't match the target it ...
4
votes
1answer
570 views

How can I use GPRename's regex feature to reinsert the matched-group into the 'replace'?

I've been using GPRename to batch-rename files; this is rather more efficient than individually correcting each file, but still seems to be less efficient than it might be, primarily because either I ...
4
votes
1answer
140 views

Custom GREP with asterisks and anchors?

I have lots of EDI files (which is pretty much a single line of gibberish text) that are about 300mb/pcs. I'm looking to pattern matching this: `*UP*605284466346 {lots of other stuff inbetween with ...
4
votes
6answers
253 views

Bash script programming: how to match pattern in string?

How I can get this whole value 7I45432ZX from below lines: PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 PW*3434*453*256*PE*UB PO*00*NE*7I4543 2ZX**20140617 This is the code I tried: grep ...
4
votes
1answer
3k views

Using Modifiers of Perl-compatible Regex (PCRE) in grep

According to grep --help and man grep, we can use the -P option in order to interpret the pattern as a Perl regular expression (PCRE, to be precise), instead of the default POSIX basic regular ...
3
votes
2answers
971 views

How can I parse a YouTube URL?

How do i extract only http://www.youtube.com/watch?v=qdRaf3-OEh4 from a URL like http://www.youtube.com/watch?v=qdRaf3-OEh4&playnext=1&list=PL4367CEDBC117AEC6&feature=results_main I ...
3
votes
3answers
2k views

grep for string not preceded by another string

Is it possible, using grep, to search for instances of John Smith but exclude instances of Mr John Smith?
3
votes
1answer
121 views

What happens if we add a dot at the end of sudo `apt-get autoremove`

sudo apt-get autoremove . OUTPUT: WARNING: The following essential packages will be removed. This should NOT be done unless you know exactly what you are doing! apt libapt-pkg4.12 (due to apt) libc6 ...
3
votes
1answer
99 views

Did grep change how it uses regexp?

I used to run commands like: find /dev | grep sd* to output a list of all the drives attached to my computer. It appears that I now have to add any random character before the star in order to get the ...
3
votes
1answer
2k views

How do I ignore a conflicting package on a regex match in apt-get?

I'm trying to install all but one of the R packages which are currently in the Ubuntu repositories: However, when I go to do so sudo apt-get install 'r-cran-*' I get an error: Some packages could ...
3
votes
3answers
2k views

regex on the shell?

I wanted to do some simple regex so i am trying to get the 16. I tried grep but i dont see how to write \1 or $1 to only output the capture data and i tried sed but i think i did it wrong due to ...
3
votes
1answer
39 views

REGEX behaves differently!

When running the following echo "abc>asf<tfg"|sed 's/.*>\(.*\)</\1/' The output is: asftfg I don't understand why tfg gets printed? My expected result is asf. Though, it works ...
3
votes
3answers
634 views

Why Kodos is not part of the available packages in Ubuntu Quantal 12.10?

I'm running the 64-bit edition of Ubuntu Quantal and I've used extensively Kodos, a user friendly regex editor. It seems that for some reasons, this package has been deleted from the Ubuntu Quantal ...
2
votes
5answers
273 views

Help to build this expression using sed

I have a text file and I need to get rid off the entire information just before the = symbol in each line, for example: The line: File 1515 = foo.txt needs to look like this: =foo.txt So, I had ...
2
votes
2answers
123 views

Regular expression that matches all multiple seperate expressions

It's admission time in India and I am trying my best to get the best college I can for engg. I have got a pdf file which contains a table which looks like It contains about 2500+ entries and I ...
2
votes
3answers
313 views

Trying to do a batch rename, can't figure out the proper RegEx

I'm trying to rename my movie collection. All of the files are currently named using dots instead of spaces, i.e. Men.in.Black.avi. I want to replace all of the dots with spaces which isn't terribly ...
2
votes
1answer
174 views

How to monitor a local file for changes, apply a RegEx replace on it and save/overwrite to a destination file?

I'd like to start a script or something that watches a text file for changes. When the file changes I want to run it through a RegEx parser to replace some text and then output the modified file to a ...
2
votes
1answer
609 views

How do you use sed to edit a CSV file?

I have a CSV file like this: hostname1 | role1 | environment | tag,list | | hostname2 | role2 | environment | tag,list,longer | | hostname3 | role3 | environment | | | I need a sed expression that ...
2
votes
1answer
45 views

Vi syntax highlighting for words followed by a parenthesis

I want to change the color of a keyword that is followed by a left parenthesis in a .R file. For instance, when I type length(), I want the word length to be highlighted (and not the parentheses), ...
2
votes
1answer
227 views

Fail2Ban Regex SSH Will not Match Auth.Log - Searched Everywhere for a Solution

Im trying to get Fail2Ban to work with the SSHD Config provided. When i run fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf The Output is as follows ...
2
votes
2answers
83 views

Change text in many files

I have a C++ project, where each file has at its beginning some lines of license. Now, that my license have changed, I need to update it in each file. I don't want to do it manually, since its lots of ...
2
votes
3answers
27 views

Searching through output of more command

When searching through the output of more command how can I search for a phrase that includes spaces in between? When I search for a phrase like "typedef struct audiodev" it doesn't find the phrase in ...
2
votes
1answer
106 views

Capture groups are ignored when renaming files

I have a number of files in this format: ##.## - File name.mp4 I want to rename them to: s##e##.mp4 This is what I came up with: rename -n "s/^(\d{2})\.(\d{2}).*/s$1e$2.mp4/" It works when I ...
2
votes
2answers
99 views

Removing a string of files with rename

I have been trying to batch rename a bunch of files so that they are consistent and fit within the name structure that I have come up with. For instance,I am renaming comics, and so I have a directory ...
2
votes
1answer
178 views

Delete lines starting with pattern from a file

I tried several commands: tr, sed but to no avail. Here's the file: > ... > ... > setEPS() > postscript('images/boxplot_default.eps') > ... > ... I want to delete those two ...
1
vote
3answers
100 views

Forming IPAddresses from Text file

I have a huge text file that contains IP addresses scrambled all over but not in one unit for example. So what the@192@ heck are you doing@168@ in my house @10@.you were not @16@ supposed to be ...
1
vote
2answers
248 views

Literal dot confusion, copy all hidden files

It works fine when I copy all hidden files using regex: cp -r source/\.[^.]* destination/ and it just copies exactly files beggining with a dot . . However, I found the following works also: cp ...
1
vote
4answers
126 views

extract text from a file using terminal?

I want to process the body of text and extract an integer from a specific position in the text, but I'm not sure how to describe that 'particular position'. Regular expressions really confuse me. I ...
1
vote
4answers
141 views

Change directory structure from /YEAR/MONTH/DAY/ to /YEAR-MONTH-DAY

I need to change my directory structure for my photos from /YEAR/MONTH/DAY/ to /YEAR-MONTH-DAY I know this can sort of be done with exiftool, but it will only work on files containing EXIF-tags, and ...
1
vote
1answer
575 views

Grep Regex match not returning result as expected

I have several Ubuntu servers and there is some behavior that has me curious. On any newly installed machine (Ubuntu Server 12.04.3 LTS), if I run: echo "testbla123" | grep -P -o [0-9]* This will ...
1
vote
2answers
65 views

Unexpected anwer from the following regex?

I have this following file:- $ cat numbers a1 12 12345 123456 19816282 1@$%6 I am using grep "^[0-9]\{1,6\}$" numbers which is giving me the following results:- 12 12345 I was expecting 1@$%6 ...
1
vote
3answers
202 views

Simple way to get all .o files but one

I'm trying to link all *.o files from another folder and would like to in my Makefile do something like; g++ *.o (folder/*.o and not folder/main.o) -o bin Is there someway I can use somekind of ...
1
vote
5answers
4k views

How to programatically remove empty new lines from a file?

I need to remove empty new lines from text file in terminal. Example file 123 123 123 123 123 123 I've searched in google a bit but only solution found was sed '/^$/d' myFile > tt and it ...
1
vote
1answer
2k views

How to make grep display only the matching regexp?

I am trying to find data from files using grep, but grep usually prints out the filename as well as the line where the term is found. In this case, I am looking for a special regexp and I want grep ...
1
vote
2answers
71 views

Exclude directories from inotifywait

Doing an inotifywait to watch a directory, and trying to exclude all subdirectories from being watched while not excluding the files. inotifywait -r -q --exclude <pattern> dir/ What to put in ...
1
vote
1answer
228 views

Undo apt-get remove --purge

I wanted a fresh install of Python and ran sudo apt-get remove --purge python. Apparently it has killed almost everything I had installed in my system. Looking at the history.log I guess I could ...
1
vote
1answer
771 views

How to replace strings in file without regex?

I need to replace some strings in files (from command line) but I don't want to use sed -i because my string contains lots of funny characters which need to be correctly escaped. Is there a way to ...