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

17
votes
5answers
382 views

How can I merge files on a line by line basis?

cat file1 foo ice two cat file2 bar cream hundred Desired output: foobar icecream twohundred I already have a solution involving a for loop with sed using the line number of the files, but in ...
14
votes
3answers
5k 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
7k 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
7k 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 ...
7
votes
6answers
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, ...
7
votes
5answers
8k 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.
6
votes
5answers
302 views

How can I edit a range of text between 2 symbols? awk, sed, regex

Using the "*" symbol, (doesn't have to be that one, any special character will do in order to indicate), how can I edit the text from this: *berry straw rasp blue boysen * blahblah blahblah blahblah ...
6
votes
2answers
12k 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
2answers
14k 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
2answers
8k 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 ...
5
votes
1answer
210 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 ...
5
votes
1answer
692 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 ...
5
votes
1answer
123 views

Bash always evaluate Regex as true

In a script, there's these lines #!/bin/bash ... if ! [[ $SCREEN_NAME =~ ^[a-zA-Z0-9_.-]+$ ]]; then echo "The Server title contains invalid symbole. Only a-z A-Z 0-9 - _ . are allowed" exit 1; ...
5
votes
1answer
5k 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 ...
4
votes
3answers
376 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
352 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
230 views

How can I extract text between parentheses containing a specific word?

How can I convert this: foo (blah) (bar 80) foo (cats) (blat 92) To this: foo bar 80 foo blat 92 I would like to keep all the text that is NOT in parentheses. I only want to extract text ...
4
votes
4answers
1k 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
1k 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
252 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
3answers
803 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 ...
4
votes
3answers
136 views

Reverse sed's/regexes' pattern-matching priority order

Consider this command: echo "string.with.dots" | sed 's/\(.*\)\.\(.*\)/\1\n\2/' (Matches into a first capturing group any character until the last . and into a second capturing group any character ...
4
votes
1answer
151 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
343 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 ...
3
votes
4answers
260 views

What is a practical way to list every character used in a file (Bash) (Regex)

How can I turn this: Johnny's penguin, (Tuxie), likes the following foods: French fries, and beef. To this: abcdefghiklnoprstuwFJT',():. (These are the total characters used in the input) ...
3
votes
2answers
1k 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
172 views

Regex Conversion

I'm wanting to make a command to edit /etc/default/grub and change the timeout from 10 to 2. Could anyone explain how to do this?
3
votes
3answers
71 views

Move pattern to beginning of line

I am trying to reformat a log file such that date and time appear at the beginning of the line. My logs look like this: blah, blah, blah, Friday, Mar 13,2015 16:59:42 yadi, yadi, yada, Friday, Mar ...
3
votes
3answers
3k 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
143 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
2answers
45 views

grep regex pattern causes unexpected command behavior

I'm searching for lines with $ and consecutively ' or " through this grep in my terminal: grep "\\$('|\")" -rin folder_path After pressing enter the terminal doesn't think the line is complete so ...
3
votes
1answer
103 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
192 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 ...
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 ...
2
votes
3answers
145 views

Remove all text before last space in text file from CLI

I want to remove everything before the last space in a text file from the CLI Example text: 2015-03-02 21:34:15 20480 dump-2015-03-02-21-34.tar The string that should remain is ...
2
votes
5answers
277 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
3answers
97 views

How do I extract a single attribute from an XML file?

I'm not really familiar with regex, sed, etc. and a bit lazy to figure it out right this moment, so how do I extract this line: <yweather:astronomy sunrise="6:50 am" sunset="7:06 pm"/> Let me ...
2
votes
2answers
152 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
38 views

adduser.conf NAME_REGEX is not working

I am trying to set a rule for new users. I changed the /etc/adduser.conf file by adding the line: NAME_REGEX="[A-Z]{1}[a-z]{5,9}$" but after that, the system is not accepting any user.. always ...
2
votes
6answers
5k 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 ...
2
votes
1answer
1k 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 ...
2
votes
3answers
377 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
2answers
104 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
2answers
39 views

How can I put a cluster lines in numeric order?

How can I convert this: -foo -bar 42 \ randomtext=00 "00" \ -randomtext=00 "00" \ -foo -bar 104 \ randomtext=00 "00" \ -foo -bar 1 \ -randomtext=00 "00" \ To this: ...
2
votes
1answer
150 views

How do I use the “^” and “$” symbols with regular expressions in a bash script?

How do I use the "^" and "$" symbols with regular expressions in a bash script? Please give me an example using both symbols.
2
votes
3answers
73 views

Regex PDF search?

I am an electronics engineer and I regularly view PDF schematics. Often I encounter the scenario where I would like to search the schematic for a component, e.g. "R1" The problem is that searching ...
2
votes
1answer
183 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
687 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 ...