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

learn more… | top users | synonyms (1)

3
votes
5answers
62 views

Non-greedy match with SED regex (emulate perl's .*?)

I want to use sed to replace anything in a string between the first AB and the first occurrence of AC (inclusive) with XXX. For example, I have this string (this string is for a test only): ...
2
votes
1answer
48 views

Can't do substitution in a sed program

Q. I want to write a 2 line program that lets me substitute "the" with "zee" and "The" with "Zee". Here is what I'm doing: I'm writing a sed program for example, program.sed. Inside it, I'm ...
1
vote
1answer
21 views

Bash Built-in Regular Expression Usage

I've tried to find all line's which begin with at least 1 tab. Several Variations didn't work out. The most Basic one: #!/bin/bash FILE=emptiness { while IFS=""; read line do regex='^[\t]+' if [[ $...
3
votes
1answer
129 views

Match RH[A-ZA-Z] with grep

How can I match with grep the regex RH[A-ZA-Z], so string includes RH with two characters that both are a letter between A and Z? I tried this but without success: yum list-security --security | ...
0
votes
0answers
46 views

Regular expression in expect command

I need to match a string and a newline with a regular expression or something like split when using the expect command on Linux. Here is the example of the command output: Notification value: 34 39 ...
0
votes
2answers
28 views

How to delete the slash using REGEX

Hello I am trying to delete the /. I have problem looks like this , find all the files with the .sh extension in the current folder and delete the ./ before the name and the .sh after the name and ...
2
votes
2answers
44 views

sed to print pattern that spans across lines

I'm learning sed and I'm currently stuck with the following problem: I want to extract the lines found between ^C's from the following output: banner exec ^C This is the banner ^C banner motd ^C ...
1
vote
1answer
36 views

Regular Expression ^$ not working on UNIX using grep command

I'm facing a problem in using the regular expression ^$ on UNIX. When I type grep '^hello$' text on the command line, as a result it should match the "hello" word because it is the only word on a ...
-1
votes
2answers
33 views

Find first unique occurance of match in file using regex

I would like to find the first unique occurrence of a match within a file. In the example data below, I would like to find the first occurrence of each Chunk Chunk 1 some text second line of random ...
-1
votes
0answers
64 views

sed replace or add variables into file

I'd like to use the following function (which is working for me): if grep -q HOSTNAME=noob hostname.ini; then sed -i "s/HOSTNAME=noob/HOSTNAME=pro/g" hostname.ini; else echo "...
1
vote
1answer
41 views

extract servers' blocks from Nginx conf

I have the following conf file for nginx: user www www; ## Default: nobody ... events { worker_connections 4096; ## Default: 1024 } http { include conf/mime.types; ... server { ...
1
vote
0answers
24 views

convert attachments of type winmail.dat (TNEF) to “real” attachments in stored email messages, recursively in MailDir

Some email messages contain the attachments in a format called TNEF (Transport_Neutral_Encapsulation_Format). This attachment is usually called winmail.dat. Extraction tools exist for linux, but ...
3
votes
2answers
158 views

`cut`: selecting columns containing a string

I have a big file with several columns on each line. I'm familiar with using cut -f -d to select specific columns by their number. I checked the manual for cut and it doesn't seem that there's a way ...
4
votes
1answer
43 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
33 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
63 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 ...
3
votes
2answers
55 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
70 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
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
27 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
44 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 ...
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
73 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
3answers
64 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 ...
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
245 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
250 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.
0
votes
1answer
43 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
1answer
46 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
177 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="/...
0
votes
3answers
63 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
39 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
29 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
40 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
40 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'...
-1
votes
4answers
41 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
35 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....
0
votes
2answers
40 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
50 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
289 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 ...
11
votes
3answers
774 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
88 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
0answers
33 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 ...
0
votes
2answers
126 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
126 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 ...
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
79 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
58 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....