Tag Info

Hot answers tagged

33

There's no reason that's preferable syntax on its own. It's sometimes used as a hack when "grepping" for a process (e.g., ps aux | grep [a]pache). Using that syntax prevents grep from matching its own command line in the process list. See How to prevent "ps" reporting its own process?


14

I consider myself a regex noob, but I created a bunch of files with variable length strings in them and I think I got what you wanted, try this: user@host$ grep -e '[^\ ]\{7,\}' * For those who don't quite understand this: -e makes grep search using a regex. [^\ ] means to match a single character except space. \{7,\} means to match a string of 7 or ...


12

Use ps Output Formatting: ps -A -o pid Output formatting of the command is the best option. The o option controls the output formatting. I listed some of arguments below below, see 'man ps' for the rest ( to use multiple it would be -o pid,cmd,flags). KEY LONG DESCRIPTION c cmd simple name of executable C pcpu ...


8

You want to use the "-L" option of grep: -L, --files-without-match Only the names of files not containing selected lines are written to standard output. Path- names are listed once per file searched. If the standard input is searched, the string ``(standard input)'' is written.


6

Sadly there doesn't seem to be a way to negate a file match in Apache. However, the regular expression library that Apache uses is PCRE (Perl Compatible Regular Expressions). This means you have the full power of Perl's regexes, including their negative lookbehind and lookahead assertions. These are fairly complicated and powerful features. I can't be ...


5

The only reason that [[:digit:]] must be used is to support locales that use digits other than 0-9. For example Arabic-Indic Numerals: ٠١٢٣٤٥٦٧٨٩ (Unicode U+0660 through U+0669). Otherwise for the Hindu-Arabic numerals 0123456789, [0-9] works equally as well as [[:digit:]].


5

Regular expressions is usually not the best tool for xml. It's usually better to use some kind of parser specially written for xml. For xml verification you may want to try xmllint tool


5

Second way is better... server { listen 80; server_name www.domain.com; return 301 $scheme://domain.com$request_uri; } Why Let me quote directly from the official Nginx wiki at http://wiki.nginx.org/Pitfalls#Taxing_Rewrites ... By using the built-in variable $request_uri, we can effectively avoid doing any capturing or matching at all, and by ...


4

# time grep -oE '[[:digit:]]' /etc/services ... real 0m0.029s user 0m0.017s sys 0m0.013s # time grep -oE '[0-9]' /etc/services ... real 0m0.029s user 0m0.016s sys 0m0.012s I could probably write a quick script to average them, and I bet I'd find that the averages are identical, but it certainly gives you the idea.


4

ps ax | awk '{ print $1; }'


4

You should have a look at this how to from the Apache documentation, I think that's what you need here: http://httpd.apache.org/docs/2.2/vhosts/mass.html The basic idea is to replace all of the static configuration with a mechanism that works it out dynamically. This has a number of advantages: Your configuration file is smaller so Apache starts ...


4

You can't do this in a hosts file as it is purely an IP-to-name mapping. It either needs to be done on the web server, or on a proxy server. Apache will allow you do to this with mod_rewrite and Squid will allow you to do it with redirectors.


4

To negate a range in a regular expression, the caret must be inside the square brackets. sed -i -r 's/$old_string([^0-9])+/$new_string/g' $FILENAME The parentheses are also unnecessary in this case if you are not using backreferences (and it doesn't look like you are.) sed -i -r 's/$old_string[^0-9]+/$new_string/g' $FILENAME One last thing: bash ...


4

(?P<name>pattern) is the standard PCRE syntax for named capture-groups - the documentation is missing a P. The "Named Subpatterns" section on Wikipedia states that (?<name>...) and (?'name'...) are valid for PCRE 7.0 onwards; presumably your version of nginx is linked against an earlier version of PCRE.


4

Just add the "L" flag. This does the inverse find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -HL 'Font' '{}' ';'


4

Use rewrite instead. Try something like RewriteEngine on RewriteCond %{HTTPS} =on RewriteCond %{REQUEST_URI} !^/system_ RewriteRule ^/(.*) http://exsite.tld/$1 [R=301,L] ought to do it. Please test it before implementing in live environment. What these rules state is: 1. enable rewrite engine, 2. check if HTTPS is on, 3. check if the URI path does not ...


3

Something like this should work: <FilesMatch "^\.(.*)$"> order allow,deny deny from all </FilesMatch> FilesMatch uses a regex there.


3

$ grep -E '^From:' /some/file | uniq


3

$ url=git://github.com/some-user/my-repo.git $ basename=$(basename $url) $ echo $basename my-repo.git $ filename=${basename%.*} $ echo $filename my-repo $ extension=${basename##*.} $ echo $extension git


3

Try this location ~ ^/[\d]{5} { # ... } ~ means the a regex location ^ means the beginning of the line [\d] is shorthand for character class matching digits {5} shows that the digits must be exactly five, no more, no less and () parentheses are not necessary if you do not want then to use grouping, $1, for example


3

As the other gentleman pointed out, the exiqgrep program is just a perl script. It takes the raw value passed to the -r function (recipient) and uses it in a pattern match. The pattern match is a simple $rcpt =~ /$opt{r}/ perl test, the default match, since it's not specified, is case sensitive. As with all things perl, TIMTOWTDI (There Is More Than One ...


2

Use the -o switch to have a cust format output ps -o pid The bad way using sed, as you explicitly asked may be ps -ax | sed 's#^\( *[0-9]\+\) .*$#\1#'


2

The best method would be to modify the data "in place" using Perl's MySQL DBI. SELECT the data, perform the regex and send it back with an UPDATE. My personal preference would be to use Python, with it's MySQLdb and re modules.


2

Trying to parse HTML with regular expressions leads to pain, just don't do it. Jeff wrote about it in Parsing Html The Cthulhu Way. "But I only want to __", doesn't matter, seriously, don't do it. Take a little time and learn something designed to parse html. I personally would recommend a Perl Module for this (such as HTML::TreeBuilder), but what ...


2

Well, not quite. You're going to miss somethings. Domain Part: \w+ matches on word characters. which is ok, until the person doesn't use the NETBIOS name but uses the domain name (fully supported) so that would match STACKOVERFLOW\Zypher ... but not STACKOVERFLOW.COM\Zypher because the . will throw off the matching. The User Part: while Goyuix has ...


2

What language are you using? In general it sounds like you want something that matches the basic aspects of a domain, ruling out the possibility of a period other than the one that delinates the .tld. #http://[^.]+\.(com|net|org)#i If you don't want to match the protocal, maybe something like this. #[^. ]+\.(com|net|org)#i Your desire to handle ...


2

If all you want is a list of ip addresses #!/bin/bash cut -d ' ' -f1 log1.txt | cut -d ':' -f2 | sort | uniq >log1.out cut -d ' ' -f1 log2.txt | cut -d ':' -f2 | sort | uniq >log2.out while read IP do sed -n /$IP/p log2.out done <log1.out


2

I'd suggest using cut, not grep: cut -d\ -f1 log1.txt | sort | uniq > ip1.txt cut -d\ -f1 log2.txt | sort | uniq > ip2.txt grep -f ip2.txt ip1.txt If the IP you're after is the second in each line, rather than the first, replace '-f1' with '-f2'. HTH.


2

According to http://www.postfix.org/header_checks.5.html you could use Perl Syntax for text replacement e.g. /^(To|Cc):.*foo@bar.com/ PREPEND Reply-To: ${1} The puzzle I've left to you is to look up the Perl RE Syntax to retrieve only the email as match. Update: In your case it's this RegExp: /^(To|Cc):\s*(\w+@\w+.\w{2,4})/ PREPEND Reply-To: ...


2

This is almost certainly the wrong approach to protecting yourselves from SQL Injection attacks. If you just look at your application code, and write protection mechanisms into the database access routines, or better yet, use a Database Abstraction Layer (one that already has injection protection), and you won't have to worry about this crappy hack. ...



Only top voted, non community-wiki answers of a minimum length are eligible