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

learn more… | top users | synonyms (1)

1
vote
2answers
485 views

linux + match IP ADDRESS with 3 octets or with 4 octets

how to match IP address with 4 octets or with 3 octets in one command? target - match xxx.xxx.xxx or xxx.xxx.xxx.xxx ( syntax should fit for Linux and Solaris ) how to merge the following commands ...
1
vote
3answers
309 views

Recursively edit files based on parent directory's name

I'm facing an issue I'm not quite sure how to overcome. I have a large directory with hundreds of folders, all following the naming scheme "a_b_x", with x being a random word. In every one of these ...
1
vote
1answer
559 views

Regular expression how to get value in shell script?

I have to write a shell script to get value from a string, something like: string="abcdef" pathName How can I use grep command with the use of regular expression to get "pathName"?
1
vote
1answer
491 views

Multiply certain numbers in a text -file by certain constant

I want an alternative solution to this jQuery hack, tasting a bit reinventing the wheel -- look I am sure I could do this with some one-liner using basic *ix tools. Look much easier and ...
1
vote
1answer
149 views

What special characters does grep parse by default? [duplicate]

Possible Duplicate: In a regular expression, which characters need escaping? I know there is the -E flag which treats the "search term" as a regular expression. However, it seems that even ...
1
vote
2answers
124 views

In-place substitution for lines matching some pattern in a given set of files

Following on from my previous question: Remove slashes/parent paths from filenames inside CSS and Javascript content I arrived at the following command which replaces any filenames in these ...
1
vote
1answer
266 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 ...
1
vote
1answer
93 views

Aptitude regex engine

I was trying to lookup the versions of libdb in the debian archives with something like that: $ aptitude search '~S~ndev$(~nlibdb~(\d~|-~)!~v~rnative)' which didn't work as expected so I changed ...
1
vote
4answers
103 views

Regexp on data flow

I want to test if in my data flow, there is something, and do an exit code. I use gammu monitor, which provides a data flow, for example : [root@MYSERVER ~]# gammu monitor Press Ctrl+C to break... ...
1
vote
2answers
78 views

Grep and sort several unsorted things in several lines (in one document)

I have a file with several unsorted things in one line which I want to put into a new file This is an example of part of the file I have: X1314448: SaMi|SM_g2554.t1 SaMi|SM_g5072.t1 Des|Des_g3808.t1 ...
1
vote
3answers
517 views

find with user variables

I am trying to call find with a few variables. So far I had this: DIRECTORY="./ " FILENAME=-regex" .*test.*" find $DIRECTORY $FILENAME Which works fine. If I change the filename to : ...
0
votes
3answers
79 views

Ignore lines containing a capital letter

Why does the following command still return some lines containing a capital letter? aspell dump master | grep ozz | grep -v '[^A-Z]'
0
votes
1answer
292 views

What does ^> mean in a grep pattern?

What does this command do? grep "<[^>]*>" inuux.xml What is searching for?
0
votes
4answers
55 views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the ...
0
votes
3answers
35 views

How can I use grep to search a file for string combinations?

What I'm trying to do is use grep to search my Apache logs. What I want is to find is every entry from a certain IP address that also has .html or .php in the line. In other words, I want to see what ...
0
votes
2answers
123 views

grep + operator

According to the grep manual: * The preceding item will be matched zero or more times. + The preceding item will be matched one or more times. Let's test it echo 'agb' | grep 'a.*b' # returns ...
0
votes
4answers
975 views

Match multiple regular expressions from a single file using awk

I'm trying to parse a HTML file using shell scripting. There are 4 different regular expressions that i need to catch: name= , age= , classs= , marks=. Using grep "name=\|age=\|class=\|marks=" ...
0
votes
1answer
479 views

rsync exclude based on file size?

Is it possible to exclude files in rsync over a certain size (e.g. over 250 MB)? And what if I also want to exclude hidden files? How would I exclude all hidden files or directories (those that ...
0
votes
2answers
310 views

Why does this regex find a match for \x63 with a pattern [\80-\BF]

I am trying to filter valid/invalid UTF-8 bytes, but I get strange results from the following regex (which is intended to handle a 3 byte form of UTF-8). I have intended the pattern should not ...
0
votes
4answers
85 views

Use grep with or [duplicate]

How do I search in a textfile with grep for the occurrence of a word or another word? I want to filter the apache log file for all lines including "bot" or "spider" cat ...
0
votes
4answers
1k views

Extract substring using regular expression on a Unix file

I have file with below contents . /ABC/RTE/AD_900_VOP_123/OPP /ABC/RTE/TRE/AD_900_VOP_145/BBB /ABC/RTE/AN_900_VFP_124/FBF /ABC/RTE/HD_900_FOP_153/WEW /ABD/RDV/AD_900_VOP_123/OPP ...
0
votes
2answers
2k views

bash - reading user variable into bash script grep

I've tried every possible combination to get this bash script working. It's part of a larger script, and it basically prompts for a username (to check if it exists) and returns the appropriate ...
0
votes
1answer
24 views

Finding all kinds of extensions referenced in a html file

Here is my problem statement : There is a folder with many html and text files. I need to recursively go through each one of them and find all kinds of file extensions referenced in these html/text ...
0
votes
4answers
389 views

Regular expression in Bash to validate IP-address

In my Python script i have a regular expression for searching IP-addresses like 0.0.0.0-255.255.255.255 in a file, it looks like this: ...
0
votes
2answers
70 views

Regex and patterns on a ksh command line

I'm wondering what's the difference between using * and .* in a regex string. I guess, * stands for "0 to n characters" but I don't see what .* stands for. For example, what is the difference ...
0
votes
1answer
103 views

How to ask for specific parameters with grep?

I need to look in /usr/share/dict/words for a 5-letter word that starts with d or D, followed by a lowercase vowel, and ends with s. I have tried everything but to no avail.
0
votes
1answer
646 views

Asking ls to only list files in a path that match a specific glob/regex

In Zsh: Is there a way to use ls to only list files and folders in the current directory that match a specific globbing or regex pattern? For example, say I have multiple files that start with the ...
0
votes
3answers
36 views

Grep lines from foe to foe2 (not included), regexp

The file is organized in entries of the form: foe, 1.... 2.... 3.... foe2, 1.... 2.... All sub-items begin with four spaces, and then text or number item. All entries like foe, begin ...
0
votes
1answer
75 views

How do I join the next line when a line matches a regex for whole document in VI?

As title, for example, I have lines like abcdefg join! abcdef no join abcdefg join! If a line matches regex ^a.+g$ then I would like them to be joined, so it would be: abcdefgjoin! abcdef no join ...
0
votes
1answer
38 views

sed how to do “or”

I have the following two lines that work ok: /\.to <\=/ s/<\=/be <\=/ /\.to_not <\=/ s/<\=/be <\=/ I would like to combine them and I tried: /\.to( |_not )<\=/ s/<\=/be ...
0
votes
3answers
100 views

Removing second colon

Trying to create a simple script that lists mass mailing by the queue number that appears in /var/log/maillog. I'm starting off with this: [root@ditirdlns01 ~]# lsMails(){ grep -i ...
0
votes
3answers
932 views

Regular Expression for finding double characters in Bash

I am looking for a regular expression that finds all occurences of double characters in a text, a listing, etc. on the command line (Bash). Main Question: Is there a simple way to look for sequences ...
0
votes
3answers
96 views

regex suggestion

echo "223255/12345678 " | grep '[0-9a-zA-Z/\-\?:\(\)\.,"\+]{1,34}' According to the regex, it can have any of 0-9 a-z A-Z / - ? : ( ) . , " + of upto 34 chars in any order. Am I ...
0
votes
1answer
108 views

Replacement in VIM with regular expression matched part unchanged

Suppose I want to append two digit numbers in my file with "some_thing". Like from this: 12 23 45 to 12_something 23_something 45_something How can I do this using regular expression ...
0
votes
1answer
31 views

Want to replace the words with space in multiple files using SED commmand [on hold]

Want to replace the words with space in multiple files using SED commmand I have a word as 'Danny' with single quotes in many of my files in multiple directories which I want to change to 'Danny ...
0
votes
1answer
33 views

Piped search queries in vim or less

I would like to be able to search a log file for lines that being with ^2014-02-18 15:30:[0-9:,]* and have UserName:someguy much later in the same line. I am sure I could do a regex to include any ...
0
votes
1answer
36 views

All occurrences of a regex get removed without using the “global” modifier

I have the following text in the file sentence.txt Linux refers to the family of Unix-like computer operating systems that use the Linux kernel. Linux can be installed on a wide variety of ...
0
votes
2answers
429 views

Rename file in Mac OS Terminal using Regex

Hundreds of images need to be renamed with a terminal command using regex on MacOS 10.9 Mavericks. The files are named this way: 0045AW489R3T(IPCAM)_0_20131124101245_931.jpg ...
0
votes
2answers
706 views

sed - how to exclude multiple patterns in the match

I have currently a set of seds that's working well except for one thing. The particular expression I'm having an issue with is: sed -i '/[^}.to]\.to[[:space:]]/ s/\(\S\)/expect(\1/' ...
0
votes
1answer
156 views

Regex awk to Cisco Interface

I would like to know if have some Sed/Grep or Awk regex to parse Cisco interface section, with specific attribute, like bellow. Content of file.txt ! interface FastEthernet0/1 no ip unreachables ! ...
0
votes
1answer
56 views

Help with understanding a regular expression

I have this regular expression \\..\\{3\\}$ I want to understand how this expression works to match a string. My thought is that it matches any 8 characters at the end of the line. Is that how this ...
0
votes
2answers
129 views

regex, only the first occurence

I have a pipelined output from free -o -m | awk '{print $4}' I want take step by step two numbers the first and the second line. So i need two regexes. I tried with ^[0-9]{1,3}$ but this match all ...
0
votes
1answer
692 views

Egrep: contains and does not contain

egrep -i '12-12.*\swarning' log.file | cless The above will produce two lines with the date 12-12, followed by random characters, a white space, then Warning and more text. 2011-12-12 textetc ...
0
votes
1answer
196 views

python regex equivalent of kwrite [ ]+ and [0-9]+

I've never been good at regular expressions. When ever I read about them, I sort of get a headache, get up from my desk, and forget what I'm doing. Attention difficulties. But when I finally started ...
0
votes
1answer
675 views

Curl and grep html text

Is there a way to grep html text from a curl request and output grab the value that is between two html tags? More specifically the input value of a form?
0
votes
2answers
184 views

bash script, printing multiple lines that matching to a specific patern

I have a log file and I'm making a script to do some actions. An action is to print a specific area of the log. Every block at the log starts with a specific time stamp and inside the block may have ...
0
votes
1answer
72 views

(e)grep and atomic grouping [comprehension question]

I am trying to understand the correct use of »atomic grouping« a.k.a. »independent subexpressions« a.k.a. »non-backtracking subpattern« [this are the terms I found ...
0
votes
1answer
60 views

Comment the if statement and the matching endif keyword

In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify ...
0
votes
1answer
371 views

How to highlight the whole log-line in color with multitail

I'm trying to use multitail to tail logs with color highlights. I defined a custom color scheme in multitail.conf, something like this: colorscheme:my-color cs_re:red:^\[E cs_re:yellow:^\[W ...
0
votes
1answer
133 views

awk extended pattern matching (embedding pattern matching in actions for already matched strings) [closed]

I want handle strings of the form: PREFIX_TYPE_N,DATA So, does the *awk (gawk, mawk, nawk) support including pattern matching in the action for already matched string? Something like this (of ...