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?


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


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

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


9

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


9

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


9

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)


8

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


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

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


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

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.


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

Since nginx 0.8.25 named captures can be used in server_name. You should use them. Here, the sub-domain will be stored in a variable called $sub. Then you will be able to reuse it in the rewrite directive : server { listen 80; server_name ~^(?<sub>\w+)\.olddomain\.com$; rewrite ^ $scheme://$sub.doma.in$request_uri? permanent; } Alternatively, ...


5

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


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

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

You can show all listening ports with: netstat --protocol=ip -nlp About your command, grep works line by line. Where did you read this syntax, it seems belong to sed.


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


5

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

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


4

You can also use perl one liners if you find you want more regular expression features than sed provides. See this link for a comparison. nik's example would look like: perl -ple 's/exp1/exp2/g' foo > foo2.txt


4

mmv is a standard linux utility to move/rename multiple files. It is available from the repos for most distributions. For your example above, you could do: mmv *-Log-*-*-*-NODATA.txt #l1.#4#3#2.log For more information, read this debaday article or the man page.


4

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.


4

Put quotes around $x everywhere it appears. for x in `find . -regex '.*/\*.*'` ; do mv "$x" `echo "$x" | sed s/\*/_/g` ; done



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