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

learn more… | top users | synonyms (1)

0
votes
1answer
13 views

error in order egrep

This is part of a code, this order is supposed to check if there is a string in the first word twice or more that is also in the last word twice or more (in arow at the last word). echo "$first $last"...
-4
votes
1answer
51 views

Difference between ~ and ! in unix shell scripting [on hold]

Which operator should be used between ~ and ! while checking a regular expression in IF condition in shell scripting?? Will there be any difference between the two cases shared below ?? case 1: if [...
1
vote
1answer
21 views

regexp with aptitude part 2

I had asked about regexp with aptitude here and that worked beautifully. Now have i386 packages also in the midst. How do I make sure that i386 packages do not come into the picture. I tried the ...
0
votes
1answer
30 views

bash regex does not recognize all groups

I need to capture groups from a regular expression. But it seems I fail at grasping the concept of the bash variable BASH_REMATCH, as I can't get some groups. Here is my code: # I want to get the ...
0
votes
0answers
19 views

how to use lynx to “print” a web page? WYSIWYG

When I printed a page, as per the manual: Printing, Mailing, and Saving rendered files to disk. Rendered HTML documents, and plain text files, may be printed using the 'p' command while ...
0
votes
3answers
31 views

Extracting only specific multiple patterns from file

I have following file: $less dummyKeyAndValue.txt apiKey=key1;some_other_data;term=abc apiKey=key2;some_other_data;some_other_data;term=def term=pqr;some_other_data;apiKey=key1 apiKey=...
0
votes
0answers
20 views

Mass rename numbered extensions? [duplicate]

I have several files in the format of: download.1 download.2 download.3 ... I'd like to rename all these in the following format: download1.exe download2.exe download3.exe Is there an easy way to ...
0
votes
3answers
53 views

How to capture contents of line up to certain string?

I have this output: Never logged in. Last login Wed Jun 22 15:12 2016 (BST) on pts/11 from host1 I need it without the (BST) on pts/11 from host1 just like that: Never logged in. Last login Wed Jun ...
9
votes
1answer
178 views

Is there an equivalent for vim's \zs in sed or perl?

In vim we can use the \zs atom to say "really begin the match right here": :%s/funnyword\zs.*$/otherword/ Is there an equivalent for sed or even perl?
1
vote
1answer
33 views

sed replacement won't work (regex)

I'm trying to remove the text before the italian word "ANDATA" in the pdf file of a bus line. I'm using this pdftotext "file.pdf" - | sed -r "s/^.*ANDATA//g" but this doesn't work. It only removes ...
0
votes
1answer
24 views

How to sed replace this end of the line?

I want to replace this end of the line [1-9] \\ \hline by [1-9] & \\ \hline where a new ampersand. Data sample The lorem ... & 1-2 & 3-4 & 5-6 & 6000 & 10000 4 \\ \hline My ...
3
votes
1answer
55 views

Why does echo “a']” | grep -E “\'” not match?

Based on this question on SO, I have discovered that: echo "a']" | grep -E "\a" Matches OK. echo "a']" | grep -E "\]" Matches OK. But: echo "a']" | grep -E "\'" Does not match. I cannot find ...
4
votes
3answers
154 views

Regex not matching file using `find` despite being valid [duplicate]

I am attempting to run this find command to match files with a camelcased name, with the goal being to put a space between adjacent lower and upper case letters, but it's not matching anything: find -...
3
votes
3answers
48 views

how to select files in a directory with the boolean operator AND

I want to select (find/grep/ls) certain files in a directory starting with certain words and ending with a certain extension. Example: bluebelt_hans_hoff.jpg bluebelt_hans_hoff.JPEG ...
0
votes
1answer
38 views

grep a certain format, is this possible?

I'm trying to find a certain unknown 11 character sequence in a huge packet capture file. The one thing I do know is that the string I'm looking has format x.x-xxxxxxx. I've been looking for a while ...
2
votes
2answers
96 views

What exactly does this script do? [duplicate]

#!/bin/bash for a in ./*.flac; do ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}" done I found this script a few days ago to convert all FLAC files in the current directory into the MP3 format. ...
-1
votes
1answer
16 views

Linux replace only user part in email pattern

I have users like below in many *sh scripts. [email protected] [email protected] [email protected] I want to replace any emails like above with [email protected] in linux. Any idea will be appreciated ?
3
votes
1answer
53 views

Edit several lines from a certain section of an INI file

I have the subversion config file (~/.subversion/servers) I need modify to add proxy information (host, port, exceptions). This file contains many sections with proxy information. I only want to ...
1
vote
1answer
28 views

How to match string with regexp and conditionally do stuff with capture groups

The idea here is to change remotes from http to ssh in all git repositories find / -type d -name '.git' 2>/dev/null | xargs -I {} $SHELL -c \ 'cd $(dirname {}) && echo $(pwd) > /tmp/log....
0
votes
1answer
35 views

Perl command line RegEx not matching

So I have a file with contents in the following format, randomString abc\/def/ghi/mno\/pq/r abc\/def\/ghi/mno\/pq/r My intention is to replace all occurrences of / with \/ between two alpha-...
3
votes
5answers
205 views

Get first pattern matching in a line not using cut

having a bunch of texts similar to this (for the purpose of test and keeping data simpler as possible): first 1 is the real 2 time the word matched 3 appeared on the previous line but is 4 the ...
0
votes
1answer
39 views

Ansible, attempting to get specific regex pattern to work with lineinfile module

As per my question above: "Ansible, attempting to get specific regex pattern to work with lineinfile module" Essentially, I'm trying to get it to work in a single play as opposed to 2 separate plays, ...
0
votes
1answer
41 views

Remove two columns of a SQL insert command in a dump file

I have a SQL dump file having several insert commands. I would like to remove, through sed or grep (or even another simple bash trick), a specific column and its equivalent data at the VALUES clause. ...
0
votes
1answer
26 views

Grep template for extracting lines where second word has only two vowels

For example, i have file with content hello world it's nice to see you amazing night what a wonderful day my name is Robert still breathing speaking bottom soul something wrong I need to match those ...
-1
votes
1answer
28 views

How to change all “x” to “y” but only before (or after) initial “z” on each line?

On each line in a text file I need to change all . characters to # characters, but only before the first = sign. So, stop processing each line after the first = sign is encountered. If easier, do the ...
0
votes
1answer
49 views

How to use grep or sed to extract multiple matches in the same line

I have a file that, amongst other things, has text like this: <TR><TD>5</TD><TD>Ukraine</TD></TR> <TR><TD>3</TD><TD>Vietnam</TD></...
1
vote
1answer
58 views

find and delete files older than specific days and have specific string in filenames

To delete files older than 5 days from a directory, we can use command. find /directory -type f -mtime +5 -delete But, in my case, I want to delete only those files having 'YYYY-MM-DD' in their ...
1
vote
2answers
29 views

How to use appropriate regex to find a pattern in awk?

Using the following example, I am trying to figure it out the regex which cover the following pattern in my awk program. The output could be only numbers no more than 5 length : i.g. 15251 The ...
1
vote
4answers
66 views

Regular expression to match floating point numbers in shell script

I'm using a regular expression to match floating point numbers: for f in $float_numbers ; do if [ $f =~ "[0-9]*\.?[0-9]*" ] ; then echo "****f is $f ****" fi done where $...
1
vote
1answer
15 views

How to do Regexp/pattern-searching in gunzipped files?

How to use regexp/pattern-searching under gunzipped files. For instance ummm... let's use - /usr/share/doc/linux-image-4.8.0-1-amd64$ zcat changelog.gz | less Now the way I use is when reading the ...
0
votes
2answers
32 views

Sed and regex, same pattern on same line two different groups?

I have some data looking similar to this: BLACK Harry<-George->Edna<-$$$Tom<-Tom->Phil<-Tue" The data I want to use in this case is: Harry<-George->Edna<- Tom<-Tom-...
1
vote
1answer
31 views

KSH Pattern from variable does not work

Could somebody explain me why pattern in Korn shell (assigned to variable) works this way: u@h:w$ pattern='file_[0-9][0-9]' u@h:w$ ls $pattern file_01 file_02 file_03 But it doesn't work for ...
0
votes
3answers
49 views

Multiple `awk` statements with pipes `|` ?

#!/usr/bin/env bash #### Extract OS-related info from a Linux box #### #### Display header message #### # $1 - message function write_header(){ local h="$@" echo "------------------------...
0
votes
2answers
44 views

How can I replace opened brackets from end of line to new line using sed?

I have many files with wrong opened { brackets from end of line and need to replace it to new line by conditon [a-z)] [{]|[a-z)][{]. input example: public class Test { } expected output: ...
2
votes
1answer
39 views

adding a regexp filter to block a subdomain and TLD in sendmail

Running Sendmail Version 8.15.2 on Fedora 24 and lots of spam is coming in from (subdomain).(manydomains).us. I'd like to add a filter like what's available in the access file to block and .us TLD's ...
4
votes
1answer
260 views

PCRE-regex Use grep to exclude a capturing group

I am using GNU grep with the -P PCRE Regex support for matching strings from a file. The input file has lines containing strings like: FOO_1BAR.zoo.2.someString:More-RandomString (string here too): 0....
0
votes
1answer
21 views

How can I get all the ENV keys from .rb and .yml files in a directory tree?

I would like to find a way to get the unique keys that are used inside .rb and .yml files. These keys are used inside the hash ENV. So, there are files that contain things like: ENV['key'] in ...
0
votes
2answers
22 views

Run previous command with multiple replacements

Many of you probably know that the commands ^foo^bar^ or !:gs/foo/bar are useful for running the previous command with replacing the pattern "foo" with the pattern "bar". But is there a way to ...
0
votes
2answers
39 views

hat ^ symbol in grep argument

I have come across a script that is supposed to make adding a user to a linux system easier. I am fairly new to bash scripts so i am trying to figure out what each line of said script is doing. Now i ...
0
votes
1answer
39 views

Match any characters but not the string … in sed

I'm trying to remove strings surrounded by other strings (\[ and \]) in sed. I can match the start string \[ easily, but after that I wan't to match any characters including \ and ] but not if they ...
1
vote
1answer
45 views

Sed command for deleting an inclusive range of characters

I am working with a xml file that looks a bit like this <w:ins w:id="0" w:author="Nick" w:date="2016-11-23T00:16:00Z"><w:r w:rsidR="009C39E2"><w:rPr><w:ins w:id="1" w:author="...
1
vote
3answers
21 views

insert new line when negative + positive pattern is found using sed

Got a bunch of txt files that need to be cleaned and parsed properly. I need to break lines when pattern "SP." is found but not when pattern "ASSERT. SP." is found. Sample content: SP. 247 for ...
4
votes
3answers
99 views

ZSH wildcard expression limiting repetition support?

Does anyone know if there is a way to incorporate repetition constraints into ZSH wildcard expressions? For example, to match all files starting with "ABC" following by one or more numbers, using ...
0
votes
2answers
62 views

Extract UUID value from JSON returned from HTTP reply

I am trying to make a little script in shellscript that takes one serviceUuid from a response and use it. I just print the server response on a file called final.txt Now i need to extract the value ...
1
vote
1answer
29 views

sed match word1 and word2 to get word in between

Im having issues with trying to pull an ip address our of a log file call full. This is what the line in the file looks like [2016-11-10 11:22:42] NOTICE[24518] chan_sip.c: Registration from '"...
0
votes
1answer
37 views

Perl script extracting web links using regular expression

I am trying to write a script in perl and trying to extract web links using regular expression from a file called file.txt(which has list of website). I am not able to print the links. Here is my ...
1
vote
1answer
61 views

How to handle CRLF line endings in grep?

Suppose I have an arbitrary text input that contains CRLF line endings: $ curl -sI http://unix.stackexchange.com | head -4 HTTP/1.1 200 OK Cache-Control: public, max-age=60 Content-Length: 80551 ...
1
vote
1answer
46 views

Sed replace alphabet to uppercase after period

I am new to the sed command. I have just come through a sed tutorial article. Can somebody please explain this command for me (it changes alphabet to upper case after period) as I am new to sed. I ...
0
votes
1answer
24 views

sed script to limit columns to 15 characters

Been trying to wrap my regex foo around this but not doing too well. Please assist: need sed script to format file: 844388240 920009 XXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYYY 800450220 910003 ...
0
votes
0answers
29 views

How '$' works with grep command in bash [duplicate]

According to the man page of grep, Anchoring The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line. Say I have a ...