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

learn more… | top users | synonyms (1)

6
votes
4answers
158 views

How to add a header and/or footer to a sed or awk stream?

I have a bunch of output going through sed and awk. How can I prefix the output with START and suffix the answer with END? For example, if I have All this code on all these lines and all these ...
1
vote
4answers
22 views

Match regular expression between delimiters

I have a file with several different lines. I'm looking for lines that contain(more or less) pattern like this: \[.*<.*>.*\] In other words, I want the lines that have <something> ...
0
votes
1answer
55 views

How to grep the following lines from a file?

I have a file which has the names of many files in a directory in the following format: A20150824.0950-0955_jambala_CcnActiveSessionCounterJob A20150824.0945-0950_jambala_CcnActiveSessionCounterJob ...
-1
votes
1answer
34 views

sed: regular expression,how to substitute?

I have those line on a text file 36) SIGCANCEL 37) SIGLOST 38) SIGXRES 39) SIGJVM1 40) SIGJVM2 41) SIGRTMIN 42) SIGRTMIN+1 43) SIGRTMIN+2 44) SIGRTMIN+3 45) SIGRTMAX-3 46) SIGRTMAX-2 47) SIGRTMAX-1 ...
1
vote
2answers
49 views

Awk & regular expression to process pgn chess games file

Below an extract of the sample.pgn file [Event "rated blitz match"] [Site "Internet Chess Server"] [Date "2015.08.20"] [Round "?"] [White "Villain"] [Black "Hero"] [Result "0-1"] [WhiteElo "1643"] ...
2
votes
1answer
26 views

How to combine posix character classes of a regex?

I need to combine different character classes in a regular expresion used by sed. I need to match [:word:] and the minus symbol -. How does that look like? All my attempty failed at trying or ...
1
vote
0answers
20 views

what is the correct regexp for mysql filter in fail2ban?

I use the default filter file /etc/fail2ban/filter.d/mysqld-auth.conf for fail2ban service. But there are some errors in file /var/log/fail2ban.log as: Found a match for '150815 10:42:54 [Warning] ...
1
vote
1answer
44 views

How to use sed to replace keys in a file using a regex?

I would like to modify a file to replace keys, suppose these keys are in the file as: 42NM 52NM 23NO XNNM I would like to replace anything with NM, with the word "Okay". 1 #!bin/bash/ 2 3 if [ ...
4
votes
2answers
92 views

POSIX behavior of sed's ^ and $ regex anchors with multiline pattern spaces

What is the POSIX behavior of the sed ^ and $ anchors when used at the beginning and end of a regex if the pattern space contains embedded newlines, like after you use the N command? Should they ...
0
votes
2answers
33 views

AWK, SED or GREP for extracting data from HTML file

Can anyone tell me which is best to use to extract the following data from a html file which was received with curl . <script>document.getElementById("test-summary").innerHTML = ...
5
votes
3answers
46 views

Censor text with regex

I'm currently running this command to censor an indented to-do list. sed -e 's/\(\s\+- \)\(.*\)/\1XXX/g' It's great except that I'd like the number of Xs to match the number of matched characters. ...
0
votes
1answer
57 views

What's wrong with this grep?

> output2.txt cd # some directory i'm trying to search find views/shared -type f -name "*.js" -print0 | while IFS= read -r -d $'\0' line; do echo -n "${line%.js}" | tee -a ...
1
vote
3answers
38 views

Remove words (letters followed by space) from a specific column

I have a file and the format is as follows: cat dog AHF123432 | 123432 | dhfshfjdh lion AFG23412 |23412 | dfshjhfjdhj I need to remove those words from first column which contains only alphabets ...
3
votes
1answer
41 views

What is the effect of the underscore in [A-Z] [_a-zA-Z0-9]*?

In regards to regular-expressions what is the effect of the underscore in [A-Z][_a-zA-Z0-9]*
1
vote
1answer
51 views

Bash script with “execute” command and strange regexp

So I was looking through Paul Irish's dotfiles and found reference to this bash script: #!/bin/bash cd "$(dirname "$BASH_SOURCE")" \ && source 'utils.sh' declare -a FILES_TO_SYMLINK=( ...
1
vote
1answer
33 views

How to express “There is a specified symbol in the following unknown numbers of characters” in regex(vim)?

I have many python code examples in my markdown files, which should be prepended with >>> symbols. So I write a vim function to do this job: function AddShellPrompt() range let lnum = ...
2
votes
1answer
58 views

How to use regex inside exec with find?

Is it possible to use regular expressions based on the result (file name) inside the exec argument with find? I want to be able to "exec" based on parts of the argument, like: find . -name pattern ...
1
vote
1answer
43 views

grep also returning non matching lines

I'm trying to grep the output of strings and only find lines that start with a certain number of = chars. I tried strings data.txt | grep ^=* Sample output: 1~{, WX2 };K,< ========== ...
1
vote
2answers
49 views

Grep and ignoring leading whitespace

I've been working on a bash script to search for names of defines, and then grab the hex values for them and put them in the list. Once I have the list of names I'll attempt to search for "#define ...
4
votes
6answers
374 views

Grep the text which matches with a pattern

I was looking for a command which will print the selected portion of a line which matches the conditions. Eg, my text line is like this: p1=X||p2=Y||p3=X||p4=X||p5=X||p6=Y||p7=X I want to print ...
0
votes
1answer
35 views

sed - find string made of 4 numbers with a preceding character and append character

I'm trying to build a sed command that will allow me to search and replace some values in a large csv file. I have this column which contains years, like 2005 - 2006 2001 - 2003 and so on, but I also ...
1
vote
0answers
36 views

LFTP exclude file extensions

I am trying to mirror directories with lftp but I don't want to download filetypes that are notoriously large like .mp4 and .swf. But I am having trouble with the regex - and seeming like the ...
1
vote
1answer
23 views

Locate --regex with negative lookahead

Problem I tried to implement a negative lookahead when searching a file with locate like this: locate --regex "apple(?!t)" However I'm getting the following error, because there seems to be some ...
2
votes
4answers
280 views

Replace regex match with string containing match

I have a file with text as Afghanistan=+93 Albania=+355 Algeria=+213 American Samoa=+1 Andorra=+376 Angola=+244 It has all the country list and its dialing code. I want to replace: ...
2
votes
5answers
294 views

Duplicate lines and make them unique?

I have the following structure of text lines: 3923 001 L05 LV,L05 RM 3923 002 L12 RA,L12 LA 3923 003 I06 ALL 3923 004 G04 RV,Z09 ALL but i would need this: 3923 001 L05 LV 3923 001 ...
1
vote
2answers
97 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 ...
1
vote
1answer
74 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 The only way I could do it was ...
0
votes
2answers
39 views

grep for lines/files that contain exactly X chars

Here's the output of a grep command I ran: [user@localhost] : ~/Documents/challenge $ grep -i -e ".\{32\}" fileA fileB fileA:W0mMhUcRRnG8dcghE4qvk3JA9lGt8nDl fileB:observacion = new Observacion(); ...
0
votes
1answer
25 views

emacs dired regexp mark files beginning with

In Emacs Dired mode, I'd like to mark directories and files whose names begin with Addr but not files that contain Addr inside the name. I'm using RE-Builder to test my regular expressions and am ...
0
votes
2answers
29 views

Delete folders using regex

I would like to delete folders with specified regex, but I could not build a good regex. I have: /root /my-picture-2015 /my-picture-2015-1 /my-picture-2015-2 /my-picture-2015-1 ...
2
votes
5answers
152 views

Testing if files start with certain letters and contain no special character except for period at end next to file extension in a shell script

I have a shell script that runs a for loop to execute a command on multiple text files in a folder. I want to test if these files' names start with a specific set of letters (NA for instance), and ...
2
votes
1answer
43 views

How do I match the beginning of a line in a manpage?

When I do man zshbuiltins I typically want to search for a command. Suppose I'm looking for info on the alias command. I get a chunk of text like: : [ arg ... ] This command does ...
3
votes
3answers
122 views

Undo letterspacing with sed

I have a source text file containing text where some words are l e t t e r s p a c e d like the word "letterspaced" in this question (i.e., there is a space character between the letters of the word. ...
2
votes
1answer
37 views

Move up every other line to end of line containing character

I have ran 2 xpath queries piped together to retrieve certain information. However the results came out formatted on separate lines when I want them to be on the same line. So for example the lines ...
1
vote
1answer
47 views

regex usage in exim filtering

I'm trying to create an exim filter to block spam messages containing " 85% OFF" in the subject line. That's a blank space, then any two digits, then the percent sign, a blank space and the ...
1
vote
4answers
121 views

Delete everything before / on every line

I am trying to delete certain 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-6753067355c6 ...
0
votes
1answer
29 views

Wrap all lines with character sequence in vim

So basically I copy/pasted some code, and I need to prepend and append some more code to each line. Each line is a function call, and is getting added to a switch statement as it's own case. Right ...
0
votes
2answers
80 views

get values which only ocurre once in the vector

there is a vector of numbers I have which ascend (it is called t8_) 2 7 8 9 11 15 34 91 91 92 94 the problem is that some number happen two times - I don't want to remove them but they have to ...
4
votes
2answers
155 views

How to search for and replace text between two markers in bash script, with content from another file?

Say I had a block of text in the ~/.bashrc: #~/.bashrc # ...some commands... # aliases alias suicide='sudo rm -rf /' # end aliases # other commands I wish to replace that block of text with some ...
0
votes
1answer
75 views

Remove the exact same matching lines with sed

I have this bash script: sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie main/d' /etc/apt/sources.list sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie\-updates main/d' ...
0
votes
3answers
48 views

Shell pattern matching and arithmetic operators (+ - * / %)

This looks so simple but it isn't: [[ "1234+5678" =~ [0-9]+(\s*(\-|\*)\s*[0-9]+)* ]] && echo $? returns a 0. However, it actually should not do that, as only minus (-) and multiplication (*) ...
2
votes
1answer
85 views

Match a number range with grep

I need to find all processes that have in their names a number between 100 and 200 inclusive. I tried ps -ef | grep xclock -bw '[1-2][0-9][0-9]' but that includes 299. How to suppress it and ...
0
votes
2answers
97 views

Extract just the hostname and port number from tnsnames.ora file

I would like to give a hostname, and get a port number in return. My tnsnames.ora file looks like: DELUCA = (DESCRIPTION = (ADDRESS = (COMMUNITY = TCP.world)(PROTOCOL = TCP)(Host = ...
0
votes
1answer
32 views

Find directory names with N occurences of a set of characters

Sorry in advance, I know there are hundreds of posts about find, but I genuinely don't understand what's happening here and haven't been able to find a definitive answer to this question: how to match ...
0
votes
2answers
55 views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want ...
0
votes
3answers
45 views

match same lines

I've an file which I need to know if this file has entries which are the same The file contains entries like this: dn: cn=ccb2fa1a-6efb-4f29-b18b-72e226d76935,ou=Named,ou=Identities,ou=Active,o ...
0
votes
1answer
46 views

What does “\(\)” stand for in this command: grep(“-(mean|std)\(\)”, x[,2])

Need to know about the function of \(\) in grep("-(mean|std)\(\)", x[,2])
0
votes
2answers
64 views

Find all characters “[1-777])” at the beginning of the line

Pseudocommand perl -pe 'g/^[1-777])/g' data.txt where I try to all numbers at the beginning of a line with ")" following them etc 1), 67) and 777). Data where all question numbers should (etc 1), ...
1
vote
3answers
72 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. ...
3
votes
1answer
180 views

Regex for crontab validation

I need to check in bash whether an entry into the crontab file is valid. Is there a crontab command switch? I can extract individual lines and try to control individual items through regex. But I ...