An open community 
of Macintosh users,
for Macintosh users.

FineTunedMac Dashboard widget now available! Download Here

Topic Options
#17702 - 09/30/11 09:58 AM regular expressions question
Virtual1 Offline


Registered: 08/04/09
Loc: Iowa
I've been unable to get the "?" operator to work in SED. It works fine in GREP. Example:

echo "nathan" | sed "s/na[t]\{0,1\}han/_/g"
_
(that works)

echo "nathan" | sed "s/na[t]\?han/_/g"
nathan
(that doesn't work)

/? and /{0,1\} should be functionally identical, zero or one matches of the preceding pattern. Both work in GREP, but only the range one works in SED, and I can't find any explanation for why. I've tried different variations of escaping, quoting, and options like -E and -e.
_________________________
I work for the Department of Redundancy Department

Top
#17705 - 09/30/11 10:58 AM Re: regular expressions question [Re: Virtual1]
Hal Itosis Offline


Registered: 09/03/09
Loc: 10.6.8 (build 10K549)
Originally Posted By: Virtual1
I've been unable to get the "?" operator to work in SED. It works fine in GREP. Example:

echo "nathan" | sed "s/na[t]\{0,1\}han/_/g"
_
(that works)

echo "nathan" | sed "s/na[t]\?han/_/g"
nathan
(that doesn't work)

/? and /{0,1\} should be functionally identical, zero or one matches of the preceding pattern. Both work in GREP, but only the range one works in SED, and I can't find any explanation for why. I've tried different variations of escaping, quoting, and options like -E and -e.

There are 2 classes of regular expressions: BRE and ERE (basic and extended).

? by itself has no special meaning in BRE.
Nor does + nor | nor ( nor )

the original grep didn't support ERE either... so egrep was developed.
nowadays grep can do both by virtue of the -E flag ... and the same should now be true for sed as well.

i.e., try sed -E

[unless you post examples of the the sed -E expression you've already tried... we can't see what went wrong.]


Edited by Hal Itosis (09/30/11 11:20 AM)

Top
#17706 - 09/30/11 11:14 AM Re: regular expressions question [Re: Virtual1]
Hal Itosis Offline


Registered: 09/03/09
Loc: 10.6.8 (build 10K549)
at first blush, my guess is that you escaped the question mark \? in what was supposed to be an ERE:
Originally Posted By: Virtual1
echo "nathan" | sed "s/na[t]\?han/_/g"

e.g., does this do what you want?

echo "nathan" |sed -E "s/na[t]?han/_/g"


Edited by Hal Itosis (09/30/11 11:20 AM)

Top
#17712 - 09/30/11 01:09 PM Re: regular expressions question [Re: Hal Itosis]
Virtual1 Offline


Registered: 08/04/09
Loc: Iowa
thanks hal, that was evidently the only combination of quotes, escaping, and flags that I had somehow missed.

cat "klone report.txt" | sed "s/Thu Sep 29 ..:..:.. CDT 2011[ ]*[0-9]* KB remains, \(( STALLED ) at [-]\{0,1\}[0|1] KB\/sec current, \)\{0,1\}[0-9]\{2,4\}:..:..:.. at [0-9]* \(KB\/sec current, ..:..:..:.. at [0-9]* \)\{0,1\}KB\/sec average //g" | sed "s/^ditto: //g" | sed "s/: Input\/output error$//g" | sed "s/^\(\/[^\/]*\)\{3\}//g"

looks slightly better as

cat "klone report.txt" | sed -E "s/Thu Sep 29 ..:..:.. CDT 2011[ ]*[0-9]* KB remains, \(( STALLED ) at [-]?[0|1] KB\/sec current, \)?[0-9]\{2,4\}:..:..:.. at [0-9]* \(KB\/sec current, ..:..:..:.. at [0-9]* \)?KB\/sec average //g" | sed "s/^ditto: //g" | sed "s/: Input\/output error$//g" | sed "s/^\(\/[^\/]*\)\{3\}//g"

While I was swinging through the vines on the internet (googling) I ran into a fun saying, something akin to "a regular expression is something that looks like someone vomited on your keyboard" smile
_________________________
I work for the Department of Redundancy Department

Top
#17713 - 09/30/11 01:16 PM Re: regular expressions question [Re: Virtual1]
Virtual1 Offline


Registered: 08/04/09
Loc: Iowa
and to somewhat save face/embarrassment from my use of regular expressions, here's my big momma:


echo "Displaying any unexpected entries in /var/log/wired.log ..." ; echo ; cat /var/log/wired.log | grep -v -e "[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Debug: *" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Sent \\([0-9]\+\(\.[0-9]\+\)\? \(bytes\|KB\|MB\|GB\|TB\)/[0-9]\+\(\.[0-9]\+\)\? \(bytes\|KB\|MB\|GB\|TB\) ([0-9]\+/[0-9]\+ bytes)\\|[0-9]\+/[0-9]\+ bytes\\) of \"\\([^\"]*\"\\)\\+ to [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Disconnect from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Indexed [0-9]\+ files and [0-9]\+ directories for a total of \\([0-9]\+\(\.[0-9]\+\)\? \(bytes\|KB\|MB\|GB\|TB\) ([0-9]\+ bytes)\\|[0-9]\+ bytes\\) in [0-9]\+\(\.[0-9]\+\)\? seconds$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Indexing files\.\.\.$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Signal USR2 received, indexing files$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Sending \"\\([^\"]*\"\\)\\+ to [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Login from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} succeeded$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Login from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} using Wired Client 1\.[2-3]\(\.[0-9]\)\? on \(Mac OS X\|Darwin\) [0-9]\+\.[0-9]\+\(\.[0-9]\+\)\? (\(i386\|ppc\|powerpc\)) succeeded$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Login from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} using Wire [1-9]\.[0-9][0-9]\?\.[0-9][0-9]\?\(-[0-9][0-9]\?\)\? on Linux [^ ]* ([^\)]*) succeeded$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Could not read command from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: No route to host$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Connect from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Could not read command from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Operating as user wired (120), group [A-Za-z]\+ ([0-9]\+)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Listening on :: ports [0-9]\+-[0-9]\+$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Listening on 0\.0\.0\.0 ports [0-9]\+-[0-9]\+$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Starting Wired version 1.3.[1-4] ([0-9]\+)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Started as /Library/Wired/wired -d /Library/Wired -l \(-u \)\?-L /var/log/wired.log \(-s daemon \)\+-X$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Reading etc/wired.conf$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Reading /Library/Wired/etc/wired.conf$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Signal TERM received, quitting$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} moved \"\\([^\"]*\"\\)\\+ to \"\\([^\"]*\"\\)\\+$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} deleted \"\\([^\"]*\"\\)\\+$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} created \"\\([^\"]*\"\\)\\+$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Receiving \"\\([^\"]*\"\\)\\+ from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Received \\([0-9]\+\(\.[0-9]\+\)\? \(bytes\|KB\|MB\|GB\|TB\)/[0-9]\+\(\.[0-9]\+\)\? \(bytes\|KB\|MB\|GB\|TB\) ([0-9]\+/[0-9]\+ bytes)\\|[0-9]\+/[0-9]\+ bytes\\) of \"\\([^\"]*\"\\)\\+ from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Could not read command from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Connection reset by peer$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} modified the user "[^/]*"$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Login from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} failed: Wrong password$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} deleted the user "[^/]*"$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} kicked [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Login from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} failed: No such account$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\} created the user "[^/]*"$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Signal HUP received, reloading configuration$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Signal PIPE received, ignoring$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not read info for [^:]\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not read type for \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not open \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not read from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not list \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not rename \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not move \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not create \(/[^/]\+\)\+: File exists$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not write download to [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not write download to [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Broken pipe$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Timed out waiting to write download to [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: End of file$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not open \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a TLS connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: Could not read command from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: SSL: Want read$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: sleeping and trying again$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a TLS connection for 127.0.0.1: s3_pkt.c:297: SSL3_GET_RECORD: wrong version number (267)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not open \(/[^/]\+\)\+: Permission denied$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Skipping index of \(/[^/]\+\)\+: Permission denied$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not read type for \(/[^/]\+\)\+: Not a directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not delete \(/[^/]\+\)\+: Directory not empty$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Skipping index of \(/[^/]\+\)\+: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not create \(/[^/]\+\)\+: File exists$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not rename \(/[^/]\+\)\+: Permission denied$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not receive \(/[^/]\+\)\+ from [^/]*/[^/]*/[1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Transfer exists$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not delete \(/[^/]\+\)\+: Permission denied$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not delete wired.pid: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Warning: Could not rename files.index~ to files.index: No such file or directory$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a TLS connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: s3_pkt.c:297: SSL3_GET_RECORD: wrong version number (267)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a TLS connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Connection reset by peer$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a TLS connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: End of file$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not write download to [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Resource temporarily unavailable$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not read upload from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Resource temporarily unavailable$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not read upload from [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Operation timed out$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not open \(/[^/]\+\)\+: Permission denied$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not read download from \(/[^/]\+\)\+: Unknown error domain: 0$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: Connection reset by peer$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not accept a connection for [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: s3_pkt.c:297: SSL3_GET_RECORD: wrong version number (267)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Could not write download to [1-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}\.[0-9][0-9]\{0,2\}: s3_pkt.c:730: SSL3_WRITE_PENDING: bad write retry (127)$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Info: signalling stop$" -e "^[A-Z][a-z]\{2\} \([ 12][0-9]\|3[01]\) \([0-1][0-9]\|2[0-3]\):[0-5][0-9]:[0-5][0-9] wired\[[1-9][0-9]*\]: Error: Assertion failed at /Users/morris/Projects[^$]*$"

Now imagine debugging that. And to answer the inevitable for the love of God, why??, this is a great way to scan a large verbose log file for unexpected entries. It simply matches out everything it expects, in as specific a form as possible, leaving behind anything unexpected, which is good when it's not YOUR program generating the log entries and you have no idea what an "unexpected" entry may wind up looking like. This hits up a log file that's typically 200,000 lines and may from time to time display a line or three that's unexpected that I need to investigate.
_________________________
I work for the Department of Redundancy Department

Top
#17726 - 09/30/11 10:23 PM Re: regular expressions question [Re: Virtual1]
Hal Itosis Offline


Registered: 09/03/09
Loc: 10.6.8 (build 10K549)
smile shocked smile shocked crazy

Without even examining that RE, i just said a silent prayer to the Unix god(s) that there must be an easier way to do that. tongue


I can however take the oldest cheap-shot in the book...
Originally Posted By: Virtual1
cat /var/log/wired.log | grep -v -e "expression"

If there's a file involved, we don't need cat and the pipe... just grep by itself works:

grep -v -e "expression" /var/log/wired.log

Top

Moderator:  alternaut, cyn