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

learn more… | top users | synonyms (1)

0
votes
0answers
10 views

Bash: Regex for validating web URLs

I have been trying to use the following REGEX in BASH or within PYTHON. Still no luck. ...
0
votes
1answer
15 views

Add time from all log files using bash

I want to extract time from all of my .log files and add all of these times into a single entity. My log files are placed in nested directories. Directory structure for my log files: |-- temp-system ...
3
votes
2answers
26 views

Using 'rename' & regex to edit filenames

I'm new to regular expression, and am trying to use regex to rename some files. I am using rename (this one) to rename said files. Below is an example command. $ rename -n 's/\(feat.//' *.mp3 (-n ...
4
votes
2answers
261 views

How can I grep two things where one has option -w?

I have a json file from where I want to get the value of two items which are in an array using grep. Let's say I'm trying to get data from values foo and bar, the problem is that baralso matches ...
10
votes
3answers
665 views

How do you remove dot character from string without calling sed or awk again?

I have a file called hostlist.txt that contains text like this: host1.mydomain.com host2.mydomain.com anotherhost www.mydomain.com login.mydomain.com somehost host3.mydomain.com I have the ...
2
votes
2answers
35 views

grep for single quote and double quote in a string

so i am trying to write a grep which finds the .epl file names or file paths in a given file. I have tried the follwoing regexs Part 1 : REGEX Used grep -rEco "/(.+).epl|(.+).epl" ./index.epl Result ...
0
votes
0answers
11 views

How to match Markdown Setext headers in in exuberant ctags

I am working on a language definition for pandoc markdown in ctags. However, I have problems matching Setext headers in the regex which obviously are defined by multiple = or - in a new line under the ...
0
votes
2answers
64 views

Credit card number validation with bash

I have used the following regular expression to detect the valid card numbers. [2-6][0-9]{3}([ -]?)[0-9]{4}([ -]?)[0-9]{4}([ -]?)[0-9]{3,4}([ -]?)[0-9]{0,3}[^a-zA-Z] But it does not detect the ...
3
votes
2answers
62 views

How can I parse an ini file whose values may contain certain characters?

I have looked at a couple bash ini parsing scripts and I've seen this one used a few times here so I'm trying to see if it will work for me. It looks like it reads the ini file line by line multiple ...
3
votes
0answers
52 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 ...
1
vote
7answers
65 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 ...
0
votes
1answer
27 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} ...
0
votes
1answer
25 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
31 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][^,]*,' < ...
4
votes
3answers
292 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
39 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
686 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 ...
1
vote
1answer
50 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
36 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
194 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 ...
0
votes
2answers
46 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
35 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
42 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
78 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
189 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
29 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
257 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
35 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
275 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
95 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
48 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
57 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
35 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
21 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
37 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
50 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
646 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
62 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
34 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
91 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
72 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
237 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 ...
1
vote
2answers
49 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
16 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 ...