Tag Info

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?


12

It figures you're starting the contents of the location block. It figures wrong. Wrap it in quotes: location ~ "^/i/gallery2/(\d{1,4})(.*)$" {


12

You should use anchor, and in rsync the anchor character is '/'. So in your string should be: rsync -a --include="/.includeme" --exclude="/.*" ./ DEST


11

You probably want sed 's/exp1/exp2/g' foo.txt > foo2.txt Read more at Sed tutorial, Another tutorial, and A small tutorial at Linux HOWTOs


11

GNU find by default uses emacs regular expressions, you can change that type with -regextype option (see man find). If you use -regextype posix-egrep your expression seems to work. You could then also probably reduce the pattern to ^.+(jpg|gif|exe)$ With emacs: find . -regex '.+\(jpg\|gif\|exe\)$' . See this section of emacs manual for those specific ...


11

There is, unsurprisingly, a tool for this: grepcidr. It is not included by default with any system I'm aware of, but you can download it from here, and it is in both the Ubuntu package repository and the FreeBSD ports collection as well. (Version 2.0 works with IPv6 networks too)


11

Well, after almost a day of hair pulling, I finally understand a) how to do it and b) a misconception I have about sec. In reading the sec man page and it describes desc= as essentially showing the match. So in my mind, that meant it should show whatever was matched in pattern. Well, yes, that is true, in this case the match in that pattern is the; ...


10

Because when you grep for [j]ava, the process is named 'grep [j]ava'. '[j]ava' doesn't match the regex '[j]ava', and thus doesn't show up in the results.


10

I used to write perl scripts to do this, until I discovered the rename command. It accepts a perl regex to do the rename: for this, I just typed two commands: rename 's/(\w+)-(\w+)-(\d\d)-(\d{4})-NODATA.txt\$1.$4$3$2.log$//' * rename 'y/A-Z/a-z/' *.log


8

This is what I use: for GUI grepWin: link text for superfast commandline: gsar.exe from link text


8

I believe that this website may help you greatly: http://regex101.com/r/uP4nT1


8

According to nginx documentation: Then regular expressions are checked, in the order of their appearance in the configuration file. The search of regular expressions terminates on the first match, and the corresponding configuration is used. In your configuration, the following location is defined before the one with the proxy_pass and it matches ...


8

First thought is "Don't block websites". This is fundamentally a management/HR problem, not a technical one. If you really have problems with employees screwing-off instead of getting their work done, time for new employees. No that isn't a pleasant process, but I absolutely guarantee you'll be happier, more productive, and more profitable in the long run. ...


7

Use bash variables and a for loop: for i in *;do mv $i ${i%0000777};done when you surround the variable name with {} and add a % sign, it returns the value of the variable with everything after the % removed. If you use a # sign it will remove from the beginning of the string. so for i in *;do mv $i ${i#thumb_};done Would strip the thumb_ off the front.


7

These appear to be settings internal to the PCRE engine in order to limit the maximum amount of memory/time spent on trying to match some text to a pattern. The pcreapi manpage does little to explain it in layman's terms: The match_limit field provides a means of preventing PCRE from using up a vast amount of resources when running patterns that are ...


7

DNS doesn't. But the most popular bind9 nameserver daemon supports this kind of syntax in its zone files: $GENERATE 1-99 www$ CNAME www$.other-domain.com. Beware that this is incompatible with other DNS server software.


7

Just use the -v option: myproc | grep -v requests


6

You might be better off using a tool like awk. awk '/^----+$/ {flag=1;next} /Disconnected from Server/{flag=0} flag {print}' See: http://nixtip.wordpress.com/2010/10/12/print-lines-between-two-patterns-the-awk-way/


6

Use the -o option in grep. Eg: $ echo "foobarbaz" | grep -o 'b[aeiou]r' bar


6

Define another failregex (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(:.*)$ I tested this regex with fail2ban-regex and is working.


5

You could also use awk instead. With awk you can easily use Boolean constructs. getsebool -a | awk '/ftp/ && /home/ {print}' # case insensitive getsebool -a | awk 'tolower($0)~/ftp/ && tolower($0)~/home/ {print}'


5

Your %d format specifier is forcing printf to print an integer value. If you change it to %f then it would print the full number. You can use %.nf to limit the number of decimal places printed so %.1f would print one decimal place.


5

$ 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


5

do { local $^I='.bak'; # see perlvar(1) local @ARGV=("file"); while(<>){ s/<value>/<value>/ig; print; } }; Beware though: $^I like perl's -i isn't crashproof.


5

I think the following Perl regexp matches what you want: (?!.*msg-[-0-9]{4,16}\.html?$).*\.html?$ However AFAIK there isn't any place where bash supports Perl regexps. The =~ operator only supports extended regexps¹, which don't include zero-width lookahead assertions such as (?=…) and (?!…). It is theoretically possible to convert a regexp with ...


5

Let's see, how about... for f in *.mpg; do touch -r "$f" "${f}.m4v" done No need for regexps, just to take the problem from the right side. It's much easier to circle through *.mpg and add .m4v to them than the contrary, although you could also write it the other way without regexps (just for fun): for f in *.m4v; do touch -r "${f%\.m4v}" "$f" done ...


5

Wow, I was so close ... single quotes: $ ack-grep '\> \\' Figured this out after confirming that my regex match was valid using: http://regexpal.com/ and just happened to have had single quotes from trying something else.


5

This also works: $ ack-grep '> \\' and so does: $ ack-grep "> \\\\" The greater-than doesn't need to be escaped.


5

First use the '-n' flag to suppress automatic output. Next use sed addresses to quote the part you are interested at (from the dashes "---" till a line that has the word "Disconnected"). Finally print the pattern space (all the pattern space since you're interested in everything inside it). ~$ sed -n '/^---*/,/Disconnected/{p}' inputfile Edited because ...



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