Hot answers tagged

32

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?


16

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 ...


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 ...


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.


7

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 ...


6

$ 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


6

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 Double quotes because curley ...


6

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 ...


5

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


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

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 doesn'...


5

(?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

# 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

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

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

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


3

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


3

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 ...


3

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#'


3

This should do the trick on OpenSSH 5.5 and greater. Host *.* Hostname %h Host * Hostname %h.domain.com IdentityFile /path/to/keyfile.pem The first rule matches any normal domain names and just passes the domain name through. The second rule handles single word hosts and appends domain.com to the end. One side effect of this is that even for ssh ...


3

Correct regexp: (ignorefolder1|folder1/ingnorefile1). But your expression works too. Using a backslash to escape a non-metacharacter is an error. "/" is not a metacharacter and does not need to be escaped.


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 ...


3

You can specify different server blocks to different hostnames like AD7six suggested. In your case, I would write 2 server blocks, one for string1.mysite.com and string2.mysite.com and another without the server_name filter to match all other requests. Something like this: server { listen 80 default_server; listen ...


3

Curly braces like semi-colons have a special meaning in nginx's configuration thus you must turn your regex into an explicit string by surrounding it with either single or double quotes. map $query_string $edgars_access_denied { default "200"; "~mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" "403"; }


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

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 multi-...



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