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.


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


5

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


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

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

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

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

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

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


2

Assuming that the CSV file is valid (i.e. fields containing commas are quoted), you should rather use something which actually parses it as CSV. The following simple Python script will extract the second column of each row. python -c 'import csv; import sys; [sys.stdout.write(row[1]+"\n") for row in csv.reader(sys.stdin)]'


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 sounds like a problem best solved by DNS. Add this to your /etc/resolv.conf: search domain.com If a DNS lookup contains no dots1 or returns an NXDOMAIN response then another DNS lookup will be made with that search value appended. Examples: If you do ssh srv1, the DNS lookup will be made for srv1.domain.com. If you do ssh srv1.dc1, the DNS lookup ...


2

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


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

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

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

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


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

In main.cf: header_checks = regexp:/etc/postfix/header_checks and in /etc/postfix/header_checks: /^X-Source-Dir:\s(abc|def)/ REJECT due to spam: Then reload postfix with sudo postfix reload. The change I made to your regex was to remove the dots and replace the slash with a pipe.


2

The manpage does not show such option, but the exiqgrep utility is a perl script whose source you can modify to fit your needs: 114 sub selection() { 115 foreach my $msg (keys(%id)) { 116 if ($opt{f}) { 117 # Match sender address 118 next unless ($id{$msg}{from} =~ /$opt{f}/); # here 119 } 120 if ($opt{r}) { 121 # Match any ...


1

Mike's answer is correct. Consider turning on the RewriteLog to observe what mod_rewrite is actually doing. This will give you much better insight into what your rules should actually look like. Also, putting (.*)$ on the end of a RewriteCond is unnecessary and inefficient unless you're actually planning to use the value of %1 in a later RewriteRule.


1

Ordinary regular expressions don't include a way to negate anything except a single character, so I think you'll have to provide the whole list of codes you do want: HTTP[^"]*" (1|20[12356]|3|4|5) Perl-compatible REs do allow you to negate strings of text, so if you were using those you could use HTTP[^"]*" (?!(200|204))


1

Seconded Kyle comment. Anyway, if the pattern is sufficiently uniform, you can achieve what you want my matching anything but the closing character, i.e. egrep "\[#([^]]*)#\]" ... This pattern will not work if you have closing ] inside the text, e.g. [#xyz]#] will not match.


1

You can use the DBI module with the DBD::mysql driver to access the database for reading and writing, and just loop through the rows you're interested in. The documentation should be enough to give you a decent start, but it could be a good idea to back things up before you break stuff.


1

You will probably be fine with that, though there are a couple of things to be aware of: First, according to this TechNet article, the following is a list of characters that are not allowed in a username. Here it is in PowerShell: '( ; : " <> * + = \\ | ? , )' -imatch '\w' It returns false, so your \w should be fine. Second, as a possible ...



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