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

learn more… | top users | synonyms (1)

1
vote
1answer
21 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 '"...
-1
votes
1answer
32 views

replace characters inside a regex subexpression [on hold]

I'm processing a large CSV file with the deimiter ; - however, some of the text fields have the ; character inside them. I figure that I can use sed and possibly tr with some regex to deduce the real ...
0
votes
1answer
31 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
46 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
40 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
21 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
28 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 ...
4
votes
4answers
163 views

Double quote value assignments stored in a CSV?

I have a file that contains text as follows: dt=2016-06-30,path=path1,site=US,mobile=1 dt=2016-06-21,path=path2,site=UK,mobile=0 I want to convert it to text with double-quoted values in the key-...
3
votes
1answer
26 views

RegEx in bash to extract string after the first delimiter

This question is not a duplicate of any other questions around here as I need a regex in bash with the =~ matching. Assuming I have a string like string="ananas1kiwi2apple1banana2tree" The regEx I ...
1
vote
0answers
23 views

Grep every string inside specific X string [duplicate]

I want every string inside $this->translate('') or $this->translate(""), I've come up with grep -oe "\$this\->translate(\(['\"].*['\"]\))" -r dir/path but this is bringing results like $...
1
vote
1answer
24 views

How do I use this regex with grep?

I'm new to regex and found a command on a regex tutorial/test site that will allow me to search for 3 consecutive consonants. The only problem is I can't figure out how to use it with grep. Would ...
0
votes
2answers
29 views

Delete multiple patterns of files using one command (find)

I am trying to find and delete files in current directory and subdirectories (recursively) which match different patterns and print the matching files to stdout to know which ones are deleted. For ...
2
votes
1answer
47 views

How do I turn accented lowercase letters to uppercase? - Using the 'tr' command [duplicate]

I'm tryed with: $ echo 'Ciência' | tr 'a-z' 'A-Z' CIêNCIA But the 'ê' character does not change, obviously because it is accentuated. Then I tried with POSIX classes: echo "Ciência" | tr '[:lower:]'...
1
vote
3answers
33 views

grep expression to find a number

I would like to find a number in the host name. Usually the hostname of the servers is something like below host01.host.name host02.host.name I want to get the 2 number characters before the first ...
4
votes
2answers
355 views

How to display numbers only at the end of a variable in bash?

This is actually not my question, someone asked about this in a facebook group but nobody was able to answer it, so there are some variables: x="abcde12345" y="s'ldfsd[opsk12345" z="...
3
votes
1answer
34 views

awk a variable as a regex

The question is really simple, I have read all the questions and still cannot make it! I have a plain file like this $cat file1.txt ALA AJD KSF And I want awk to use each of the values as regex to ...
1
vote
2answers
63 views

Replace %p with %pK in linux kernel code

I am maintaing a linux driver and I want to replace all %p in driver with %pK. For doing this i used following command. grep "%p[^K]" -Rl . | xargs sed -i 's/%p[^K]/%pK/g' It fails in below case. %...
0
votes
4answers
38 views

Regular expression within single quotes- lose their value? [closed]

The book I am reading - Learning the Bash Shell by O'Reilly specifies some code as follows: if [ -n "$(echo $1 | grep '^-[0-9][0-9]*$')" ]; then howmany=$1 shift .... .... etc ...
1
vote
2answers
38 views

grab text out of vtt file

vtt files look like this: WEBVTT 1 00:00:00.096 --> 00:00:05.047 you're the four functions if you would of management first of all you have the planning 2 00:00:06.002 --> 00:00:10.079 the ...
0
votes
1answer
48 views

inverse regex in awk

I am trying to filter out the lines containing a particular word. The regex is command line input to the script. $0 ~ regex { //Do something. } Sample input is: **String** **number** domain 1 ...
1
vote
3answers
68 views

AWK negative regular expression

I am looking to have a awk regular expression that can give all strings not matching a particular word. using /^((?!word \+).)*/ works in java but does not work in AWK. Get compilation failed ...
1
vote
1answer
47 views

Grep starting from a fixed text, until the first blank line

I have a file prova.txt like this: Start to grab from here: 1 fix1 fix2 fix3 fix4 random1 random2 random3 random4 extra1 extra2 bla Start to grab from here: 2 fix1 fix2 fix3 fix4 random1546 ...
1
vote
3answers
45 views

how to filter inner quotes? [closed]

is it possible to filter, i.e to put ESC in front of the inner quotes with sed, awk or other *NIX tool (no perl/python)? Example (revised): $ echo label=\"123 \"456\" 789\" \"AB C\" e f gh | magic-...
1
vote
0answers
48 views

Make rofi match like dmenu

I was using dmenu for some time but it's ugly so I switched to rofi -dmenu, and there is an issue that I'm really annoyed about. The problem is with the order of matching. Let's say I have the ...
1
vote
2answers
36 views

less pattern - endswith [ ] or $

Refer to can-i-get-individual-man-pages-for-the-bash-builtin-commands: bashman () { man bash | less -p "^ $1 "; } This function will jump to the desired bash manual parameter section directly. ...
2
votes
0answers
26 views

How do you search through flags in the manpages?

Whenever I search the manpages, I'm almost always trying to find out what's going on with a specific flag. For example, when searching the man pages for pandoc I was searching the for -f flag. I'm not ...
1
vote
2answers
22 views

find and regex - find files with names starting with given name

I need a regex expression to use along with find to find all the files which name start with a given string, for example proc. I tried with find . -regex '^proc*' but it gives me no results.
1
vote
3answers
31 views

retrieving host name from email address

I am trying to go through individual emails and retrieve the host name. Each email has a To: section with an email address "[email protected]". I'm trying to retrieve just "aol.com" Eg: To: abc123@aol....
4
votes
1answer
143 views

Perl regex get word between a pattern

I have a working perl regex using grep. I am trying to understand how it works. Here is the command command. grep -oP '(?<=location>)[^<]+' testFile1.xml Here are the contents of ...
0
votes
0answers
28 views

Replacement of strings using regex with sed

I am trying to replace this: mysqli_query($query_tpl2,$linkid_log); with: mysqli_query($linkid_log,$query_tpl2); where query can be anything (any word, that is). I have this seemingly working reg ...
1
vote
2answers
64 views

Find files with extensions given in arguments using regex

Let's say a have a following command search /home/user proc .h .c .txt ... I am building a script with find command to get all files that start with given name and end with one of given extensions. ...
0
votes
2answers
27 views

Replacing string with other string

In line((s) that originate from csv file) 14/Feb/2016:15:21:33-0500]http://map1.link.de/mk what is the easiest part to replace/delete&add ]http://map1.link.de/ with , having in mind that ...
3
votes
3answers
141 views

Not working “+” in grep regex syntax [duplicate]

I'm on Ubuntu 16.04 Trying: grep '.*' file1 Output: file nu-mber o-ne second string Trying: grep '.+' file1 Output is absent Why plus is not working?
-2
votes
2answers
44 views

How can I replace this madness? [closed]

How can I replace an instance of id="ogwb" with id="ogwb" name="ogwb" value="<?php echo htmlspecialchars($_POST['ogwb']); ?>" using sed or alternative?
-4
votes
2answers
31 views

grep -E mismatching subdomains with mailids

In my Apache access log I want to find all URLs matching *.google.com. I tried this with grep -E *.google.com but it also matched [email protected], which is not desired. How do I avoid this?
0
votes
1answer
24 views

regex - block Email addresses with any capital letters Email account names

I'd like to set one line of spam blacklist rule in Email server, blocking email addresses containing any capital letters with the Email account name. How should I set it? Rule file content for ...
1
vote
1answer
46 views

how to get list of sites/domains linked to in wireshark

I have been trying to figure out how many sites does firefox connect wth and for that have been using wireshark. What I have done is made a new profile and whenever I run firefox in the browser it is ...
3
votes
3answers
53 views

How to process awk line matches?

I have a file with some lines of data that I want to extract. I'm thinking awk is a good fit for this. In pseudocode I'm imagining doing something like: Find match for line I want to process with awk ...
1
vote
1answer
36 views

pax, invalid replacement string option

I'm having a little trouble understanding what's happening in a Perl script that uses pax. Background: Feeding a .tgz file to pax and unpacking to get a folder full of files. This is the thing I don'...
1
vote
1answer
24 views

Why is my offlineimap folderfilter not working?

I have a series of folders that I deleted from my SMTP server but they still exist on my local machine. I'd like to keep them from syncing to the server. The folders all follow a pretty basic naming ...
0
votes
1answer
35 views

Swap two strings separeted by a symbol in multiple files of a directory

I want to change a string like author - name in some books to name - author. I'm trying ls * | sed -r 's/(.+) - (.+).pdf/mv \2 - \1.pdf/' | sh Maybe its a mix of Switch two arbitrary length strings ...
0
votes
0answers
25 views

grep | line with same starting and ending character in ubuntu [duplicate]

i am trying to find a line from a file starting and ending with same character i have tried $grep "^.*.$" file but is does not gives desired output
3
votes
1answer
80 views

Rename files in linux using regex pattern

I want to rename many files like Tum Hi Ho [www.DJMaza.Com].mp3 to Tum Hi Ho.mp3 To do so, I used this command. But somehow it is not working. `rename -n 's/(.*)([.*])(\.mp3)/$1$3/' *.mp3`
0
votes
3answers
53 views

Grep regex need help

Hi I have a file with 5 digits zipcodes. I am trying to use grep to print the zip codes starting 9 and can only contain digits between 4-7 The command I am using is grep '[4-7], 9'$ ...
0
votes
2answers
35 views

How to grep for alphabets followed by a space and a punctuation mark?

I have a line called 10909101 - testingName - Log8767, File787 - 8:50PM Now I just want to use grep to get testingName as my output. The first number may vary in terms of number of digits(...
2
votes
2answers
65 views

Sed regex for a variable word on Ubuntu 14

Given a file with the following string: fastcgi_param WP_ENV staging; I need an sed expression that will replace the word 'staging' with a new string: fastcgi_param WP_ENV production; In the first ...
0
votes
5answers
86 views

What does “grep -v ”^.$“” do

I have a script for cleaning up of data files The command: for i in `find /ddomain/data/shop12/ -mtime +15 -print|grep -v "^.$" |grep data-` I tried running the command without the grep -v function ...
0
votes
2answers
37 views

How to output a specific paragraph based on a pattern? [duplicate]

I have a sample file below: # This is a test file. This is a test file. This is a test file This is a test file. This is a test file. This is a test file. This is a test file. # Need to output ...
1
vote
2answers
33 views

Sed error replacing partial string with variable [duplicate]

I have 3 text files. I want to search file3 for a string in file2 and replace it with a string in file1 in found. I need to append a custom tag from file1 to the end of the string in file3, replacing ...
1
vote
1answer
24 views

How do I use sed to create a bulleted list?

I have the following list: ➜ cat list.txt job titles site reliability engineer automation automation engineer automation architect integration specialists I want to ...