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

learn more… | top users | synonyms (1)

0
votes
1answer
22 views

Regex matching on awk in command line

I'm trying to get the filename from unrar command verbose and deleting them all through command line. The unrar command output is similar to this: Extracting BucketSort.cpp ...
0
votes
2answers
17 views

sed + add comment to IP - only if IP is matched exactly

my target is to add "#" to the IP's with sed, But Only if IP is matched exactly!!! for example: sed 's/72.16.90.12/#72.16.90.12/g' /etc/hosts more /etc/hosts 72.16.90.121 host1 ...
1
vote
1answer
21 views

sed + update 4 different IP's in hosts file in one sed command

how to run the follwoing sed command in one command line? sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts ...
4
votes
4answers
600 views

Delete folders whose name has 4 digit numbers two times

I want to delete folders using regexp in a Mac terminal. 0129_0140 (no delete) 0140_0140 (delete) 0150_0160 (no delete) 0170_0170 (delete) I just want to delete folders such as 0140_0140 , ...
0
votes
2answers
41 views

Collecting network information

I need to collect information about the network usage of each process. Nethogs presents the data I need in real time, I am trying to save the output to a file in order parse it and plot the data. ...
1
vote
3answers
111 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
0
votes
2answers
26 views

Joining certain lines of text together before modifying them

I have a cricket commentary like - 0.3 Richardson to RG Sharma, 2 runs, gentle, non-swinging length ball on off, Rohit seeks to pick it up. Hit high on the bat and spooned over the returning Mitch ...
0
votes
0answers
3 views

Python script to convert adblock list in a forbidden file for Polipo proxy (regex) [migrated]

On my system I currently running Polipo proxy, mainly for adblock purposes. By a search on internet I've found many shell scripts to convert adblock plus lists in Polipo forbidden file format; most of ...
0
votes
2answers
31 views

find command from regular expression

I have question about regular expression. There are two commands. find / -regex '.*[^-_./0-9a-zA-Z].*' find / If I'm right, these two commands should output same results. Because, the first ...
2
votes
2answers
34 views

vim find and replace around a string

In VIM, if, for example, I have the text http://a.com http://b.com is it possible to find all lines (the whole line) and replace it with something before and after it, such as: <a ...
2
votes
5answers
482 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
-1
votes
2answers
39 views

scp a file to multiple folders

I wanted to scp file.txt to remote box my-remote-vm-1 In my-remote-vm-1 there are two folders conf-1-ver-2,conf-2-ver-2. The integer part in the folder name can go from [0-9]. What would be the best ...
1
vote
2answers
31 views

Postfix: Remove References to Server Software

Every time my postfix servers sent emails at the destination the emails headers include the following: by suppaserver.example.dev (Postfix) with ESMTPSA id 79D412E1A3A How can I remove the ...
1
vote
3answers
26 views

How do I replace this pattern with a newline inside it? [duplicate]

If I have a text file with this content: someline <!--\ file first read on 2015/01/11 And I want to delete <!--\ and everything until what comes after "on", how do I do it? The ...
3
votes
3answers
44 views

backreferences in `rename` regex

I have A LOT of files named "bar_foo.txt" in a directory, and I'd like to rename them to "foo_bar.txt" instead. In sed and vim the regex to to this would be something like ...
-2
votes
0answers
21 views

Complex sed Command for Insert Command [migrated]

I have a bunch of php files which have many insert commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is insert into users (ch_id, num_value) values ...
1
vote
1answer
21 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
1
vote
1answer
33 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
8
votes
2answers
57 views

What does [[.ch.]] mean in a regex?

Alternate title: What is a "collating sequence" or "collating element" in a POSIX-compliant regex? I found the exact technical definition in Section 9.3.5 of the POSIX specs, as item #4 in the list, ...
0
votes
2answers
47 views

perl: Replace string in file with double quotes

Following up question from http://unix.stackexchange.com/a/254637/18887 I have the following string in a bash variable This rule forbids throwing string literals or interpolations. While JavaScript ...
2
votes
2answers
47 views

sed to match pattern between matching curly braces

From a pattern such as [string 1]{string 2} I want to extract string 2, the string between the last pair of matching curly braces -- that is delete [string 1] and the open { and close }. My ...
4
votes
2answers
64 views

BSD sed: Replace only the Nth occurrence of a pattern

Using BSD sed; How can I perform the following substitution?: Before: hello hello hello hello hello hello After: hello world hello hello hello hello In other words; how can I replace only the ...
2
votes
1answer
47 views

Regular Expression to match (not x) and y (!x & y)

I received a desktop day-to-day calendar with puzzles. One such puzzle was deciphering a quote where the letters were substituted with symbols. I used some RegExs to find longer words, then used the ...
1
vote
2answers
71 views

Complex sed Command with AND/OR/NOT

I have a bunch of php files which have many select commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is select * from users where abc='xyz' and ...
1
vote
3answers
109 views

regex matching and substring extraction

I have these files, manually created by many different people are coming in. Formatting, although following a certain rule, is not uniform. think of these three lines below ...
0
votes
1answer
24 views

Replacing in files with sed using regex

i want to replace a string in many files like "Total:*points" using sed. I simply don't know how to use sed with regex. Below is what i got. Thank you in advance! find ./ -iname "skp-corr-*.txt" ...
0
votes
1answer
33 views

Substitution with Regular Expressions in gedit

Say I want to remove all digits from a text file using gedit 3.10.4 advanced_find 3.6.0 I have selected the Advanced Find/Replace plugin to support regular expressions out of an internet search. ...
0
votes
2answers
32 views

Why doesn't this find command work? Regex & Find variants for .mp3 .wav and .m4a files

2015.10.25 Move on and Be Blessed.wav dummy.m4a 2015.11.17 BS Full.wav.mp3 2015.11.17 BS MOL.wav.mp3 find . -name '*.mp3' -o -name '*.wav' -o -name ...
1
vote
4answers
50 views

bash extract a substring from “1.2.3-SNAPSHOT”

How can I substring a 1.2.3 from a 1.2.3-SNAPSHOT from bash? I tried echo '1.2.3-SNAPSHOT' | grep -o "^.*(?=(\-SNAPSHOT$))" but it didn't work Ideally I'd like a command to return 1.2.3 in both ...
2
votes
1answer
44 views

Extract URL from non-formatted text

I've found only examples on extracting substrings from formatted text like HTML files, but in my case I need to output a list of URLs for example: ... https://twitter.com/user1/status/xyza ...
1
vote
2answers
292 views

Any non-whitespace regular expression

Im trying to match a string agains a regular expression inside an if statement on bash. Code below: var='big' If [[ $var =~ ^b\S+[a-z]$ ]]; then echo $var else echo 'none' fi Match should be a ...
3
votes
4answers
63 views

Bulk data generation

I need to generate nearly 1 Billion records of unique integers. I tried with awk but it is not generating more than 5million records. Please help. Below is what I had tried so far - awk -v ...
1
vote
2answers
25 views

sed to match zero or more number of spaces in a string

function getVal { sedPattern='s/^.*"keyVal":"\([^"]*\)".*$/\1/' finalSedPattern=${sedPattern/keyVal/$2} echo $(sed $finalSedPattern <<< $1) } This is my Json parser written using ...
4
votes
1answer
118 views

In POSIX sed, does the period (dot) match a newline in a multiline pattern space?

In GNU sed it works. For example, this matches two blank lines in a multiline pattern space (created with N) /^\n$/ Is this standard?
1
vote
2answers
14 views

bash regex to find and save string from file

I'm a noob, so thanks for your assistance. Need some bash help... My file, hi.html, has many lines of text. I need to hunt down the line that starts with Hello abc123 blah blah blah and then save ...
4
votes
1answer
36 views

Bash regular expression pattern matching spaces, within double brackets test, using “~=” operator

Simply said, I just can't find a way to match a variable against some pattern containing spaces. Here is what I expected to work (echo 'ok' string) item='foobar baz' pat=".+bar baz" if [[ "$item" =~ ...
6
votes
2answers
414 views

Why does [0-9]* match where there aren't any digits?

so the command is : echo "abc 123" | sed "s/[0-9]*/h/g" and im getting output as hahbhch h how am i getting this output? the output i expected it to be is abc h which im getting by ...
4
votes
2answers
175 views

Bash regex capture group

I'm trying to match multiple alphanumeric values (this number could vary) from a string and save them to a bash capture group array. However, I'm only getting the first match: mystring1='<link ...
6
votes
2answers
180 views

Match the next pattern which is less than the previous match

I've got a file with QR-code lines and I want to grep for only those whose subsequences do not increase in length. Example: This one is good because the next sequence is less or same as previous: ...
1
vote
3answers
193 views

How to match two lines at once in vim

I have a file that contains records with tab separated format but in two lines, I want to arrange records in one line with tab separated values using vim editor pattern match. Ex. Abc PQR ...
0
votes
2answers
38 views

Parameter expansion in grep

To retrieve strings of the following pattern from a text file populated with multiple entries: entry=G_1234 entry=G_5678 entry=G_2345 The following grep statement doesn't provide any result grep ...
4
votes
3answers
168 views

How to replace text in a column

I have a huge file (more than 2 GB) where data is like below. 12,324,32342,E:fsdsf,23432,34534,45345,324 13,3224,342,E:werwefsdsf,23432,34534,45345,324 121,3244,33442,E:,23432,34534,45345,324 ...
3
votes
2answers
57 views

Replace only on the first matching line with sed

Using BSD sed (no GNU extensions), how can I perform an operation similar to the example provided below, but where instead of the line number, the replacement is performed on the first line in which a ...
5
votes
3answers
240 views

egrep regular expression - same word in the beginning and end

I want to find all the lines that have the same word in the beginning and in the end of the line. For example: goodword fgdlakj 3t sfkl 43lk fkl goodword bad sfa;lk3t dgk;gs 34;kl ...
5
votes
3answers
165 views

OR in `expr match`

I'm confused as to why this does not match: expr match Unauthenticated123 '^(Unauthenticated|Authenticated).*' it outputs 0.
2
votes
3answers
48 views

How to extract particular field from rows from a file, based on matching subsequent rows

I am trying to replicate a workplace problem. I have a xml file like below [~]$ less -N sample.xml 1 <SOURCE BUSINESSNAME ="" NAME ="TABLE1" FOO="ABCD"..... > 2 <SOURCEFIELD ...
0
votes
4answers
40 views

How to remove a first character of that particular sentences from a list of output [duplicate]

grep /var/log /etc/rsyslog.conf | awk '{print $2}' Output: /var/log/messages /var/log/secure -/var/log/maillog /var/log/cron -/var/log/spooler /var/log/boot.log I want the result to be: ...
14
votes
1answer
713 views

How to “grep” for line length *not* in a given range?

NOTE: This question is the complement of this Q&A: How to "grep" for line length in a given range? How can we grep for lines that have less than 8 or more than 63 characters, none ...
0
votes
1answer
30 views

Regex on multiple files

Very new to regex and have a directory of files that I would like run this regex on but don't know how. help would be great. This is the regex: (?<=#).*
7
votes
5answers
1k views

How to find lines containing more than 100 characters and contains “if”?

So, probably I should use grep for this. As long as I need recursive search I should use grep -r. But then I don't know what should I do next ;) How can I do that?