Regex/egrep matching numbers in brackets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex/egrep matching numbers in brackets
# 1  
Old 07-19-2011
Regex/egrep matching numbers in brackets

Experts:

I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it.

I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match.
"Jul 16 00:01:34 webseal1 xinetd[5465]: Reading included configuration file"

This works well enough for me, but doesn't wildcard the PID
egrep -i "xinetd\[5465\]: Reading" filename

This is what I've tried. Obviously I'm not getting it.
egrep -i "xinetd\[\[0-9\]\]: Reading" filename
egrep -i "xinetd\[0-9\]: Reading" filename
egrep -i "xinetd\[[:digit:]\]: Reading" filename

And many other variants. I've done much googling to no avail. Could someone help me out?
Thanks in advance
# 2  
Old 07-19-2011
Try:
Code:
egrep -i 'xinetd\[[0-9]+\]: Reading' filename

# 3  
Old 07-19-2011
Thanks much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Regex matching with grep -l

I am trying to find patterns in files using grep -l -e. I specifically am searching for abc. I want any file that has abc in it, but not just the letters abc. I am searching for a pattern a followed by b followed by c. I have tried egrep -l and also I have tried the following: grep -el... (2 Replies)
Discussion started by: newbie2010
2 Replies

2. Homework & Coursework Questions

Sed, matching nested brackets and deleting

1. The problem statement, all variables and given/known data: I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested. The input-file is: aaa { bbb ccc { ddd eee } fff { ... (2 Replies)
Discussion started by: FuzzyGnome
2 Replies

3. Shell Programming and Scripting

Perl match multiple numbers from a variable similar to egrep

I want to match the number exactly from the variable which has multiple numbers seperated by pipe symbol similar to search in egrep.below is the code which i tried #!/usr/bin/perl my $searchnum = $ARGV; my $num = "148|1|0|256"; print $num; if ($searchnum =~ /$num/) { print "found"; }... (2 Replies)
Discussion started by: kar_333
2 Replies

4. Shell Programming and Scripting

Regex for HP egrep

I seem to be having an issue with an egrep command and I think its the way it is interpreting my regex. I have a test file.. ###FIND THESE### telnet /telnet `telnet -l` ###Dont FIND THESE### donotfindtelnet telnetdontfind Working Regex on Linux/Solaris egrep '\<(telnet|rcp)\>' $file ... (4 Replies)
Discussion started by: nitrobass24
4 Replies

5. UNIX for Dummies Questions & Answers

egrep getting numbers only

Hello, I am kind of a noob with unix, so i'd like some help. I am trying to get some ip address with an nmap scan and then put from the result of the scan only the ip numbers this is an example Starting Nmap 5.21 ( Nmap - Free Security Scanner For Network Exploration & Security Audits )... (3 Replies)
Discussion started by: AscaL
3 Replies

6. Shell Programming and Scripting

matching a regex using egrep not working

Hi, I'm trying to validate if a string matches a regular expression, but it is not working. Am I missing something? Do I need to scape any of the characters? if echo 'en-GB' | egrep '({1,8})(-{1,8})*' >/dev/null; then echo Valid value fi Thanks in advance (6 Replies)
Discussion started by: skrtxao
6 Replies

7. Shell Programming and Scripting

regex question using egrep

Hi, i have a a bunch of directories that are always named with six lowercase alpha's and either one or two numeric's (but no more) so for example names could be qwerty1 qwerty9 qwerty10 qwerty67 I am currently using two pattern matches to capture these names echo $DIR |... (8 Replies)
Discussion started by: rethink
8 Replies

8. Shell Programming and Scripting

AWK regex to find only numbers

Hi guys I need to find both negative and positive numbers from the following text file. And i also dont need 0. 0 8 -7 -2268 007 -07 -00 -0a0 0a0 -07a0 7a00 0a0 Can someone please give a regex to filter out the values in red. I tried a few things in awk but it didnt work... (9 Replies)
Discussion started by: sridanu
9 Replies

9. Shell Programming and Scripting

egrep regex

Hi, I have a file with some words divided into syllables by the character "|" (pipe). For example zu|ri|ghe|se.I would like a regex that matches all the words that are not divided in syllables.All the word that have no "|" pipe character.I have thought at $echo "zu|ri|ghe|se" | grep '' ... (7 Replies)
Discussion started by: and77
7 Replies

10. Shell Programming and Scripting

REGEX: Matching Null?

I'm using the URL Regex feature of Squid for allowing sites via a list of regex strings to match allowed domains. The regex was actually copied from our previous proxy solution and it seemed to "just work". But, we've recently discovered that some domains (likely due to virtual hosts or host... (2 Replies)
Discussion started by: deckard
2 Replies
Login or Register to Ask a Question