Extract data from log file in specified range of time [duplicate]

You can use sed for this. For example: $ sed -n ‘/Feb 23 13:55/,/Feb 23 14:00/p’ /var/log/mail.log Feb 23 13:55:01 messagerie postfix/smtpd[20964]: connect from localhost[127.0.0.1] Feb 23 13:55:01 messagerie postfix/smtpd[20964]: lost connection after CONNECT from localhost[127.0.0.1] Feb 23 13:55:01 messagerie postfix/smtpd[20964]: disconnect from localhost[127.0.0.1] Feb 23 13:55:01 messagerie pop3d: Connection, ip=[::ffff:127.0.0.1] … How it works … Read more

Bash script – store stderr in a variable [duplicate]

Try redirecting stderr to stdout and using $() to capture that. In other words: VAR=$((your-command-including-redirect) 2>&1) Since your command redirects stdout somewhere, it shouldn’t interfere with stderr. There might be a cleaner way to write it, but that should work. Edit: This really does work. I’ve tested it: #!/bin/bash BLAH=$(( ( echo out >&1 echo … Read more

Command substitution: backticks or dollar sign / paren enclosed? [duplicate]

There are several questions/issues here, so I’ll repeat each section of the poster’s text, block-quoted, and followed by my response. What’s the preferred syntax, and why? Or are they pretty much interchangeable? I would say that the $(some_command) form is preferred over the `some_command` form. The second form, using a pair of backquotes (the “`” … Read more

How to get Maven project version to the bash command line

The Maven Help Plugin is somehow already proposing something for this: help:evaluate evaluates Maven expressions given by the user in an interactive mode. Here is how you would invoke it on the command line to get the ${project.version}: mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate \ -Dexpression=project.version As noted in the comments by Seb T, to only print the version … Read more