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

learn more… | top users | synonyms (1)

3
votes
1answer
24 views

How do I search bash's history in vi mode for “foo.*bar”

I have my bash environment in vi mode (set -o vi). So I can type <ESC>/ followed by a word, followed by enter, and bash searches for the word in the history. Since / is also vi's method to ...
1
vote
2answers
25 views

using gsub in awk to replace a word with parentheses

Hi how can I use gsub to replace a word which has parentheses. Here I want to replace ABC(T) with ABC/G awk ' {gsub("ABC\(T\)","ABC/G")}; Print $0' "$FILENAME" > tmp.tmp && mv tmp.tmp "$...
0
votes
3answers
49 views

Vim Search and Replace - Regex

I want to perform a search and replace. A newline before any non-digit should be replaced with tab. I tried %s/\n\D/\t/g but it replaced the first character of the word following the newline, which ...
0
votes
1answer
33 views

pattern regex for apache rewrite

I have a bunch of URLs counting to thousands i need to redirect and there are thre main patterns in URL first pattern There is a dash - starting the title url and want to remove that dash e..g www....
3
votes
2answers
44 views

magic example using search and/or regex

I am trying to have the file command detect some Windows text files that were never meant to be classified by file... The best choice seems to use regex to match the line content, but I cannot find a ...
1
vote
5answers
53 views

How can I use the rename command to fix these file names?

I'm trying to change files that look like 01 Track name.mp3 into 01 - Track name.mp3 So far my futile attempts were rename '0. ' '$&- ' *.mp3 rename 's/0. /$&- /' *.mp3 rename '/0. /' '/$&...
0
votes
3answers
52 views

Find-grep for List of .tex Files?

My document.tex where I want to get the list of files, and grep those files with the term gastric \subimport{}{1.2_protocal_answers.tex} \subimport{}{2_protocol_answers.tex} 1.2_protocal_answers....
1
vote
1answer
347 views

Easy Regex on Apache Logs

I'm struggling to create a regex for Apache logs. It's for ignoreregex on Fail2ban. I'd really like to be able to put something like /house to catch all files in that directory or /house/jonross....
0
votes
0answers
30 views

shell scripting using sed

I want to compare specific string surrounded by alphanumeric and some special chars in file. For example: 5efa4083-7157-437a-ab9a-652ced2fc2ea;: AAA :;5efa4083-7157-437a-ab9a-652ced2fc2ea;BBB I ...
0
votes
1answer
24 views

Cannot find the right regex for rename

I have some TV shows stored on my Ubuntu server and I could rename them all, so Kodi can recognise them, exept one: First Episode, first Season: Name - S01E001 - Title part1 Name - S01E001 - Title ...
2
votes
1answer
42 views

How can i replace multi line string using sed? [closed]

I have tried the following command:- [root@10 bin]# cat temp asdjahskjdhajksdhjkashjahfksjdhfkjsddhflkdsjhfklsdajhfklajshdkjalsdlkjasdhkljas hskdajkdhkjas cast $recv $UE_CAPABILITY_ENQUIRY ...
8
votes
3answers
8k views

Regex alternation/or operator (foo|bar) in GNU or BSD Sed

I cannot seem to make it work. GNU sed documentation says to escape the pipe, but that doesn't work, nor does using a straight pipe without the escape. Adding parens makes no difference. $ echo '...
1
vote
3answers
61 views

grep on interactive program

I have an interactive shell-like program, that outputs a lot of irrelevant error messages, that confuse our customers. Each of these error messages are full-line messages starting with "%". So the ...
1
vote
2answers
46 views

sed: Grabbing and replacing all data between last backslash and a comma

I have data in a csv format that looks like this: F1309-042543,07/14/09 01:39:25,N/A,C:\windows\system32\netsh.exe,N/A,True F1309-042543,11/21/10 03:24:02,N/A,C:\Windows\System32\networkexplorer.dll,...
0
votes
3answers
35 views

Escaping regex sed (1 lowercase, 1 uppercase, 1 symbol, 1 number) for bash

The goal is to remove every line not containing one uppercase, one lowercase, one special character and one number from a file. I am unable to run this regex: (?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=....
3
votes
3answers
238 views

Use sed with back references

I am trying to remove a space between 2 strings, they are like this: 312.2 MB 123.34 KB 487.1 GB I want to change them to: 312.2MB 123.34KB 487.1GB I've been trying and I can get: echo "312.2 ...
2
votes
4answers
242 views

How to match “4.4” from `uname -r`?

Pseudocode [ `uname -r` =~ ^4\.4.*$ ] && echo "yes" which is, however, unsuccessful in all cases. The uname -r command gives things like 4.6.0-040600-generic as an output.
6
votes
4answers
47k views

How to use regex with AWK for string replacement?

Suppose there is some text from a file: (bookmarks ("Chapter 1 Introduction 1" "#1" ("1.1 Problem Statement and Basic Definitions 23" "#2") ("Exercises 31" "#30") ("Notes and References 42" "#34")) ) ...
0
votes
1answer
40 views

Regex in case statement [duplicate]

I'm having a hard time getting regex matches to work in a bash case statement. Example code: #!/bin/bash str=' word1 word2' echo "With grep:" echo "$str" |grep '^\s*\&...
0
votes
2answers
36 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 ...
0
votes
1answer
40 views

Using sed to extract text between two strings [duplicate]

I have to use the AdaBrowse Html generator to create a bunch of formatted files. Unfortunately, all of these files contain headers before each function or procedure that follow no consistent form of ...
1
vote
3answers
153 views

Use regex to check if particular directory has folders starting with specific word

I am writing a script that checks a certain directory for any sub-directories starting with a specific word. Here is my script thus far: #!/bin/bash function checkDirectory() { themeDirectory="/...
167
votes
5answers
362k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
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 ...
0
votes
3answers
61 views

Regex pattern to replace multiple values via sed

I have a script in which I need to parse the IP address of the localhost, and replace the 2nd octet with a different value, but the value being substituted depends on what the value currently is... ...
1
vote
1answer
33 views

substitute at beginning of line

I want to search a pattern and insert a character at the beginning of a line using regsub in TcL. I have to use TcL only Input file mna1 x a1 vss vbn nch_svt_mac nfin=nfin_n1 l=ln1 mna2 x a2 vss vbn ...
1
vote
1answer
28 views

where is AlaDelta theme hiding and how do I delete/purge/remove it

I came to know that I have an AlaDelta theme sitting/hiding somewhere on the system. I tried the following approaches - $ apt-file search aladelta with variations of aladelta in some caps, all caps ...
0
votes
0answers
28 views

What does the “pipe” command do in mailx?

When using the mailx command line utility, there is a command called pipe listed in the man page (although not visible when using the help command). What does this command do? I want to be able to ...
1
vote
3answers
39 views

How to delete whitespace surrounding equal signs in a string?

I'm trying to determine a way to delete leading and trailing whitespace surrounding the equal sign from a string. The whitespace may (or may not) be present. There may be 0, 1 or more equal signs. I'...
2
votes
2answers
65 views

grep for single quote and double quote in a string

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

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
0
votes
0answers
26 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 are defined by multiple = or - in a new line under the header ...
-1
votes
4answers
40 views

How to show previous line to matching pattern with grep and not the matching line? [duplicate]

I know I can use -A, -B and -C to show surrounding lines but all of them also show the matching line. What I'm trying to make here is so, in this example file: foo bar I'd be doing something like ...
2
votes
1answer
30 views

sed whole string replacement not working

I have two scripts ins.sh and variable.sh. variables.sh holds various key-value pairs. ins.sh #!/usr/bin/env bash set -e # Exit upon error # This script generates a 64-bit system source variables....
3
votes
2answers
47 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 ...
5
votes
2answers
287 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 ...
1
vote
7answers
72 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-...
11
votes
3answers
755 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 ...
4
votes
0answers
61 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?...
3
votes
2answers
21k views

Find all lines in a file with a certain character at a certain position

I have a lab question asking me to use grep with a regex pattern to match every word where the third letter from the beginning of the line is an "a" and save it with a redirect. How can I do that?
0
votes
2answers
92 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 ...
1
vote
1answer
89 views

LFTP exclude file extensions

I am trying to mirror directories with lftp but I don't want to download filetypes that are notoriously large like .mp4 and .swf. But I am having trouble with the regex - and seeming like the exclude-...
1
vote
2answers
5k views

Pages don't get blocked with Squid over HTTPS

I have set up Squid to block pages on my own system (i.e not on a network), and I'm trying to get SSL to work with page blocking. To this end, I've set up ssl-bump and installed the certificate to my ...
3
votes
2answers
89 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 ...
1
vote
1answer
60 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 ...
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 ...
0
votes
1answer
47 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{\...
-4
votes
1answer
33 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
696 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:...
4
votes
3answers
301 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. ...