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

-3
votes
2answers
26 views

get two files together [duplicate]

how could I get two files together like this file1.txt: ROW 1 3 5 654 56 5 56 65 6 54 4 3345 35 53 3 32 2 1 ROW2 6 65 456 67 687 78 89 657 435 34 534 5 435 5 2 file4.txt: ...
3
votes
4answers
215 views

Bash create custom string

how could in bash a pattern like ROW1 n1 n2 n3 n4 up to 300 be done with some command in bash or also just perl...the delimiter would need to be \t as above
4
votes
6answers
441 views

Grep beginning of line

I have a file with the following contents: (((jfojfojeojfow // hellow_rld (((jfojfojeojfow // hellow_rld How can I extract every line that starts with a parenthesis?
1
vote
1answer
16 views

use of patterns symbol in regular expression

I am new to regex, Can anyone explain for me the patterns: [a-fA-F\d]{30} [\d\w] [-+_~.\d\w] [-\d\w]{0,253}
3
votes
4answers
497 views

What kind of space character is this?

This is pretty weird, using a .txt document sent by a friend using Windows, I believe I have found a weird space character. If I run cat file the character appears as �� Also, I was running if [[ " ...
0
votes
3answers
53 views

Grep for a pattern in line

How can i grep for a specific pattern of numbers like 1000010000000 in a whole file - the line has to have thes numbers at the beginning not somewhere else...
1
vote
2answers
52 views

How to specify a filename while extracting audio using youtube-dl?

I can create an mp3 of a YouTube video with the following command: youtube-dl --extract-audio --audio-format mp3 http://www.youtube.com/watch?v=rtOvBOTyX00 It creates an mp3 with the following ...
-2
votes
2answers
38 views

Name files after split command

there is a large file I split in bash. I am using split -l 20000 -d "job1" "job1" where job 1 is the input file - how can I change the naming of the output so that it produces ...
0
votes
0answers
36 views

mksquashfs not excluding file

I am having issues excluding a specific file from a squashfs. I want to be able to exclude all file types ending with *.db but have had no luck. Whenever I run the mksquashfs command with the ...
2
votes
3answers
50 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 ...
3
votes
2answers
62 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 ...
0
votes
1answer
31 views

how to pass single file not list of files

I am running this command while IFS= read -r file;do split -l 20000 -d "$file" "$file";done < file.list.txt now my problem is that this accepts as input a list of files (file.list) which looks ...
2
votes
2answers
47 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: ...
1
vote
3answers
518 views

split large file in bash

How can I pass all files in a list.txt which looks like file1_1.txt file1_2.txt file1_3.txt file1_4.txt to the split command (there are other txt files in the dir) and make it return the parts ...
3
votes
3answers
191 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?
17
votes
5answers
406 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 ...
4
votes
4answers
335 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 ...
5
votes
1answer
138 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; ...
6
votes
5answers
347 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 ...
3
votes
1answer
205 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.
4
votes
3answers
207 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 ...
3
votes
4answers
269 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) ...
0
votes
1answer
69 views

How can I split a line in 2 by words/characters? (Bash) (Regex)

I would like to convert: Hello Hello Hi Hello Hello Hi Hi Hi Hi Hello To: Hello Hello Hi Hello Hello Hi Hi Hi Hi Hello I want to split a single line in 2, by having them have the closest amount ...
0
votes
3answers
91 views

Batch rename, add extra “.” character at position 3 in filename, recursively

I've been struggling to make this work but I am not very good with regex. This is what I tried to do and it didn't work (after 50 minutes, still going on with no visible change): while IFS= read -r ...
1
vote
1answer
46 views

Command-line perl regex replacement: replacement string contains utf8

Say you have a file named test.txt with the following lines: ಕದಂ.ಬ कदम्ब. Then, suppose you want to replace each dot following a devanagarI unicode character (ie in कदम्ब) with a ।. Then, you might ...
1
vote
1answer
75 views

Find and replace regular expression (matching unicode character class Devanagari) in multiple files

Say you have a file named test.txt with the following lines: ಕದಂಬ कदम्ब Then, suppose you want to replace each devanagarI unicode character (ie in कदम्ब) with a D. Then, you might think that the ...
2
votes
3answers
116 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 ...
3
votes
3answers
82 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 ...
2
votes
3answers
177 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 ...
0
votes
1answer
58 views

Excluding hidden files in locate

We have a Ubuntu NAS sharing SMB and Netatalk with some Macs and I often use locate to find my files. Unfortunately since installing Netatalk it has written tons of .AppleDouble cache files to share ...
0
votes
2answers
279 views

unable to install apache2 on precise

Below is the error while running the command: root@mycompanyname:~# apt-get install apache2* Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to ...
-1
votes
2answers
49 views

faced problem in regex

i am having a text file which contain some queries like below. leptop pencil group leptop book gruop buk grop laftop pensil laptop pancil laptop bag bok from this i just want query which start with ...
0
votes
1answer
36 views

Syntax for regex in IF statment

I'm trying to come up with the syntax for a regex in an IF statement, but I'm not quickly having success... Can anyone lend a quick hand please? if [[ "$path/$file" =~ .{txt,doc,docx,xlsx,rtf} ]]; ...
1
vote
1answer
50 views

Color the regular expression in same file

I have a big file and need to look over certain patterns. and also look for another patterns based on first pattern and thus this requires to color the lines which matches the search in the same file. ...
1
vote
3answers
238 views

One liner ffmpeg (or other) to get only resolution?

I'm not really well versed in the command line so hopefully this isn't too stupid of a question. If I run: ffmpeg -i videofile.avi I get an output such as this: ffmpeg version ...
1
vote
1answer
173 views

Why do these regular expressions in grep behave strangely?

I wanted to play a bit with a grep command using regular expressions and find out that they behave differently from what I expected. For example, for a file temp with the following content helloworld ...
-4
votes
3answers
763 views

find all headers file begin with vowels in /usr/include

I need to find all headers from /usr/include that begin with vowels (a,e,i,o,u) Example: acpi.h aclinux.h ah.h ... I don't know how to do it , I tried something with grep but I didn't make it ...
2
votes
3answers
80 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 ...
0
votes
1answer
23 views

Using grep with regex

I have a regex which works fine for me. I checked it on following site: https://www.regex101.com/ (?<=.log:)[^;]* Unfortunately it doesn't work anymore when I try to use it with grep. I try to ...
0
votes
1answer
38 views

Grep for specfic number format

I have a Unix script, which within has release numbers which are like this (2.19.0.32) Look like IP's but are not as some are like this 2.23.0.06.DBP. I've tried variations of this but comes back ...
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 ...
0
votes
0answers
57 views

header_checks in Postfix

I attempted to write a regex for header_checks to filter out To: header, but it is not working. The assumption is: if a header To: does not contain local domain names it will reject the message. ...
4
votes
3answers
398 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 ...
1
vote
4answers
511 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
2answers
496 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 ...
2
votes
1answer
77 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
950 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 ...
0
votes
1answer
65 views

Explain in details egrep line

Hi i found in the internet egrep line. The line founds the longest line in the text. But i dont understand specific elements. Maybe someone could explain me all line? Here it is: egrep -n "^.{$(wc -L ...
2
votes
2answers
90 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 ...
1
vote
2answers
2k views

How do I use regex to remove all punctuation and symbols? [closed]

I'm using Python 2.7 regex. I need to remove all symbols, punctuation, numbers and whitespace from strings in different languages. For example, these two strings: the following characters: ...