Piping tail output though grep twice

I believe the problem here is that the first grep is buffering the output which means the second grep won’t see it until the buffer is flushed. Try adding the –line-buffered option on your first grep: tail -f access_log | grep –line-buffered “127.0.0.1” | grep -v “.css” For more info, see “BashFAQ/009 — What is … Read more

How to compare two decimal numbers in bash/awk?

You can do it using Bash’s numeric context: if (( $(echo “$result1 > $result2” | bc -l) )); then bc will output 0 or 1 and the (( )) will interpret them as false or true respectively. The same thing using AWK: if (( $(echo “$result1 $result2” | awk ‘{print ($1 > $2)}’) )); then

bash script use cut command at variable and store result at another variable

The awk solution is what I would use, but if you want to understand your problems with bash, here is a revised version of your script. #!/bin/bash -vx ##config file with ip addresses like 10.10.10.1:80 file=config.txt while read line ; do ##this line is not correct, should strip :port and store to ip var ip=$( … Read more

How to use multiple commands after “||” in Bash

You can group multiple commands within { }. Saying: some_command || { command1; command2; } would execute command1 and command2 if some_command exited with a non-zero return code. {} { list; } Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. … Read more

Non-interactive SQLite3 usage from bash script

Looks like it’s as simple as #!/bin/bash sqlite3 test.db “create table n (id INTEGER PRIMARY KEY,f TEXT,l TEXT);” sqlite3 test.db “insert into n (f,l) values (‘john’,’smith’);” sqlite3 test.db “select * from n;” from https://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/

ZSH/Shell variable assignment/usage

Two things are going wrong here. Firstly, your first snippet is not doing what I think you think it is. Try removing the second line, the echo. It still prints the date, right? Because this: DATE= date +’20%y-%m-%d’ Is not a variable assignment – it’s an invocation of date with an auxiliary environment variable (the … Read more