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

learn more… | top users | synonyms (1)

4
votes
1answer
73 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an exploit?...
1
vote
7answers
80 views

Rename files add dashes after fourth and sixth characters

I have some files such as: 20150716_something-here 20150716_something-heretoo 20150716_something-hereaswell They need to be renamed as 2015-07-16_something-here 2015-07-16_something-heretoo 2015-...
0
votes
1answer
60 views

how to find and delete certain regex in geany text editor?

I have a sample text like this: \documentclass[a4paper]{article} \usepackage[a4paper,margin=2cm]{geometry} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{color} \setlength{\...
0
votes
1answer
27 views

Card Number regular expression help [closed]

I have used the following command+REGEX to list all the files contain card numbers in a set of files. grep -r -l -e '[3-6]\d{3}([\ \-]?)\d{4}([\ \-]?)\d{4}([\ \-]?)\d{3,4}' * I have tested this ...
-4
votes
1answer
34 views

Can anyone explain in detail the following two commands regular expressions

The following two commands used to count no of non-zero integers of second column in the text file. Can anyone please explain the regular expression in detail. grep -c '^[^,]*,[^0][^,]*,' < myfile....
4
votes
3answers
315 views

Remove files by regular expression

I want to keep files whose names match [0-9A-Z]{1,2}_\d{4}_\w+?\.dat, for example, A1_2001_pm23aD.dat, K_1998_12.dat, and remove the rest. However, the ls and rm commands do not support such regexes. ...
1
vote
1answer
53 views

Replacing mysql settings with sed

I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...) lines in db.txt. I have ...
4
votes
3answers
702 views

Using regex to get mouse MAC address

What would be the most handy way to grab the mouse's mac address from the following output: ~ ➜ bt-device --list Added devices: Logitech K811 (00:1F:20:EB:06:E0) Plattan ADV Wireless (5C:EB:68:1F:D1:...
1
vote
1answer
67 views

Command line tool for easy multiline regex search and replace

I use PCRE regular expressions for search and replace very often when working with a text editor and I was left quite unhappy after I found out that in powerful Unix command line tools like perl, awk ...
3
votes
2answers
99 views

Using grep with the --exclude-dir flag to exclude multiple directories

I am searching through a Ruby on Rails application for a word using grep on OSX, and I would like to exclude directories that match a certain pattern. I am using the following command: grep -inRw -...
5
votes
1answer
215 views

Grep word boundaries

Accorging to GNU documentation: ‘\<’ Match the empty string at the beginning of word. ‘\>’ Match the empty string at the end of word. My /etc/fstab looks like this: /dev/sdb1 /media/...
0
votes
2answers
59 views

Finding special characters in name

How do I find files that have ~ * and other special characters in the name? e.g. find . -name "*\*" should match "any characters" and then *, but it matches nothing; how can I get the command to ...
1
vote
2answers
42 views

Regex in find - OS X

I cannot figure out what's wrong with my regex, it seems to be working with grep but now with find. I'm trying to find all the files which follow the common expression in TV shows e.g. S02E21. find -...
2
votes
2answers
51 views

How to get numbers of specified (range of) length from string with grep?

Here I have a bash "one-liner": cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 16 | grep '[0-9]', which generate 16 lines of 16 character alphanumeric strings. Example of output: ...
1
vote
1answer
92 views

Pattern matching [duplicate]

I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression. I have the following script: #!/usr/bin/env bash # cookbook filename: ...
1
vote
1answer
50 views

egrep doesn't work as expected on SunOS system

Here is what I want to achieve on SunOS: Only pattern like [text_text=text], [text=text], [text] or text are valid patterns, where by text I mean anything in 0-9,a-z,A-Z, space, newline, tab, enter. ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
2
votes
3answers
195 views

sed regular expression behaving differently than in vim and perl?

Here's a sample 'test.txt' abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das sample desired output: X1yad X2fad X3had X4wad X5mad I could get it working in vim with: :% ...
-4
votes
2answers
27 views

only regular expressions : i want the lastnames that start with A or R [duplicate]

name ,lastname,phonenumber Hace, Apoio, 703-2101 Yoliot, Apostolos, 4222-1124 Jenny,Thano,105-4122 Aeriom,Koun, 510-4122 Dekon, Atolo, 502-2522 Feow, R,685-3431 I did this but doesnt worked and ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...
0
votes
1answer
34 views

How do I match beginning/end of string in regex?

I know that there's ^ and $ but those are for the beginning and end of line, I am trying to match the beginning and end of string/word. I tried to use \b, which didn't work. For example: echo "lol ...
5
votes
3answers
271 views

How to subtract 1 from numbers matched by regular expression?

I'm trying to write a script that reduces each number in line by "1", but I'm getting all "0"s instead: awk '{a=gensub(/([0-9]+)/,"\\1","g",$0); if(a~/[0-9]+/) {gsub(/[0-9]+/,a-1,$0);} ...
1
vote
2answers
45 views

Why is this command to open man page and perform search not working? [duplicate]

This open-man-page-and-search-for-string-in-a-single-command question half covers what I'm trying to do: Instead of doing man chmod and then /a+x to jump to the first section in the chmod man ...
5
votes
3answers
323 views

Grep exact number of digits and some other characters

I'd like to parse a file containing 5 digit numbers separated by comma or dash, lines like : 12345,23456,34567-45678,12345-23456,34567 My goal is to find lines which have incorrect formatting eg. ...
0
votes
3answers
117 views

Puppet doesn't ignore whitespace

I have an entry that may or may not appear in /etc/rsyslog.conf: # Added for Kiwi *.err;*.emerg;*.alert;*.warning;*.debug;*.notice;*.crit;*.info @10.19.24.50 Since some of these servers ...
3
votes
3answers
58 views

Grep that works with overlapping patterns

I want to count the number of repeating patterns aa in a very big file. So I use the following command: grep -o "aa" ./bwt/dblp.txt | wc -l This works, except when I have a string such as aaa, ...
2
votes
3answers
68 views

Print up to (and including) the nth occurence of a pattern in a line

Let's say I have multiple lines similar to below in a file. Turbo is a cat. cats are good. cats are not dog. Coco is a black cat. cats are furry. cats are not dog. now, if want to grep all the ^.*...
1
vote
2answers
44 views

Which of the following use of anchor is correct in regex using grep?

Both of the below commands gives the same output, however which one is the correct method to use it? grep ^'\<that\>' file.txt Searches for the line which has that as the first word grep '^\&...
1
vote
1answer
29 views

string substitution using sed

I have this string for example : asddsa "ll" sadd " fsgsg" "sdafaf" "lkkx" "fsgfgsg" I want to substitute all characters inside " " with a character x. Expected output in this case should be: ...
2
votes
1answer
22 views

Simple Regex match not working

I have the data below which I am trying to parse out the tittle with each of the following RegEx, Some Entries have a (Year) or other do not. same with the database number. is seem to get different ...
1
vote
2answers
47 views

Using sed to substitute a string containing variable integers

I have a text file and want to use sed to replace the following string (including the "s): " rel="lightbox[1846]" title=" with # The numbers between [ and ] are variable and change. I want to ...
1
vote
2answers
63 views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
2
votes
4answers
721 views

Why does the grep command ignore the period in the search string?

The command that I am using: find . -type f -name "*.sql" -exec grep -i -l 'schema_name.' {} + What I want to search is all the files which contain schema_name.. But the find command is ignoring ...
3
votes
1answer
106 views

Is there a way to use regex expressions to auto-fill filenames in bash?

Assuming I have a directory with files as shown: $ ls file0001.txt file0002.txt file0003.txt file0004.txt file0005.txt someotherfile.txt Lets say I want to run the following command: $ cat ...
0
votes
2answers
35 views

searching a file [closed]

I want to find in the system a file, and I know part name of it. How could I do that? I tried unsuccessfully the command: find / "*partname*" The problem is probably very easy however I cannot find ...
0
votes
3answers
120 views

Print start and end between two patterns excluding end of range [duplicate]

I want to use sed -n "/START PATTERN/,/END PATTERN/p" file.txt pattern to search in a file. file.txt content is ~keyword~, ~output~. ~1.~ ~output~. ~2.~ ~output~. ~keyword~, ~output~. ~1.~ ~output~. ...
1
vote
1answer
80 views

regular expression : with a variable

arrFormat=( jpg jpeg bmp tiff png ) varExtension="jpg" for elem in "${arrFormat[@]}" do   echo "${elem}"   # do something on $elem # done #for i in $( find -E . -iregex '.*\.($arrFormat)' ) ; do ...
5
votes
2answers
334 views

Case-insensitive search in awk

I need to search for a keyword using awk, but I want to perform a case-insensitive (non case sensitive) search. I think the best approach is to capitalize both the search term ("key word") and the ...
2
votes
2answers
36 views

Extracting library directories from a long variable

I declared a long variable containing the libraries to use during the compilation: export LIBS="-L/usr/lib -lcurl -L/lib -lhdf5 -Wl,-rpath,/lib -L/usr/lib64 -lglpk -Wl,-rpath,/usr/local/tools/vtk-6.1....
1
vote
2answers
52 views

SED Search and Replace on Linux [duplicate]

I want to change the value from 1521 to 1525 in FROM_HOST only in file gexhosts.cat: FROM_HOST db201521 TO_HOST db201521 Is there a way to do that or some work around? I would really prefer ...
0
votes
0answers
17 views

Different regex engines and syntax in unix tools like grep, find, vim, sed, aptitude etc [duplicate]

I would like to learn and use regex more. I made couple tutorials and trying use regex in everyday tasks. But I've found thing that demotivates me and slowing learning process - different syntax/...
0
votes
3answers
32 views

Perform regex search on a previously regex-matched line (one-liner)

I need to print a string which is in a unique line in a long text file. Example relevant line in file long.txt: Software version 4.0.10, 2002-03-28 The wanted string is exactly 4.0.10. The steps ...
0
votes
1answer
36 views

How to catch everything after prefix phrase with SED?

How to catch everything after prefix phrase with sed? Like here I wished to catch active/idle: $ sudo hdparm -C /dev/sda /dev/sda: drive state is: active/idle $ sudo hdparm -C /dev/sda | sed "s/\...
1
vote
2answers
41 views

How extract under linux some capturing groups using command line in a php/preg fashion?

Given in linux environment exists lot of packages for manipulating strings (grep, awk, sed, ...), I would like a software to extract a capturing group in a php/preg like syntax. Maybe the most close ...
1
vote
2answers
84 views

Strange “apt-get purge” behaviour with regEx

I'm running Debian (jessie) and following this question, I followed the first answer suggestion to install that packages running sudo apt-get install gtk2-engines-* gtk3-engines* That did not ...
0
votes
1answer
31 views

Does find Command Do Match For Regexp Because Of Implementation?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and jtobdops.02.cer....
0
votes
1answer
38 views

Bash group matching

I am using bash 3.1.17(1)-release and script below. It doesn't show group match for input i.e. 4fwk2_dev 2fwk5_dev echo $FWK FWK_REGEX="/(\d{1,3})fwk(\d)_dev/" if [[ $FWK =~ $FW_REGEX ]]; then ...
0
votes
2answers
38 views

sed to change dns log string format

I want to use sed to change the following text: (3)www(5)first(3)nth(6)domain(3)com(0) to: www.first.nth.domain.com Can each group between the parenthesis separators be captured and then ...
6
votes
1answer
88 views

Perl one liner to find words longer than 63 characters

I have a number of XML files containing sanskrit texts to be converted to tex. Latex has a maximum of 63 characters per word for its hyphenation to work, everything longer than that will not be ...
1
vote
1answer
36 views

pattern regex for apache rewrite rule

I have the following pattern on a few thousand lines I will like to use regex to convert to what I want RewriteRule ^/omg/deadly-venom/?$ http://www.example.com/omg/deadly-venom [L,NC,R=301] ...