date: extra operand '+%s'
I changed line 7 to: date +%s -d "$createDate".
This works because it's a GNU date, which doesn't allow you to specify an input format for the date. This fixes the error.
date: extra operand %d' error
The problem here is with date
itself. Let's see how.
You are saying:
vDate2=`date --date="2 minutes ago" +%b %d %H:%M:%S %Y`
Because you want to use
date --date="2 minutes ago" +%b %d %H:%M:%S %Y
However, if you try to run it you'll see that you get the error:
date: extra operand ‘%d’
Try 'date --help' for more information.
The problem is that you need to enclose the FORMAT controls within double quotes:
# v v
$ date --date="2 minutes ago" "+%b %d %H:%M:%S %Y"
Aug 25 14:49:31 2016
When this is done, all together your full awk
one-liner can be:
awk -v Date="$(date "+%b %d %H:%M:%S %Y")" \
-v Date2="$(date --date="2 minutes ago" "+%b %d %H:%M:%S %Y")" \
'$5 > Date && $5 < Date2' file
Note I am using -v Date="$(date ...)"
:
$( )
for process substitution, since backticks ` are almost deprecated, ir at least considered legacy.date=" things "
to prevent errors if the content has spaces.v var=value
using spaces after-v
, since-vvar=value
is gawk-specific.
Error with the date command in Bash
Following from my comment, your problem is that you cannot assign the result of the date
command as you have it written, you need:
time=$(date +"%Y-%m-%d %T,%3N")
Output format for dates in a range, with bash
When you use the FORMAT="%m/%d/%Y %H:%M"
you need quotes because it contains a space, so:
now=`$DATE +"$FORMAT" -d "$now + 1 day"`
Also, I do not think that you can compare dates like that. You might need timestamp:
date +%s
Couldn't figure out the error at printing custom timestamp in shell script using date?
In
echo $(date -d $n_incr +%s%N)
$n_incr
is expanded to
echo $(date -d +10 mins +%s%N)
Note that +10 mins
is not a single argument, but two.
The fix is to quote the argument:
echo $(date -d "$n_incr" +%s%N)
You can also omit $n_incr
:
echo $(date -d "+$lp_incr mins" +%s%N)
Related Topics
A Way to Prevent Bash from Parsing Command Line W/Out Using Escape Symbols
Why Do I Get /Etc/Cups Conflicts Between Attempted Installs in Yocto
Determine Vm Size of Process Killed by Oom-Killer
Comparison of Cat Pipe Awk Operation to Awk Command on a File
Gnuplot Doesn't Work Through Ssh Command
How to Switch to Root User Without Entering Password in Bash Script on Redhat
Linux - Dependency Libmysqlclient.So.15 Not Found
After Segfault: Is There a Way, to Check If Pointer Is Still Valid
Problems with Accessing Command Line Arguments in Linux from X86 Asm
How to Mail Script Output in Table Format
Install Binaries into /Bin, /Sbin, /Usr/Bin and /Usr/Sbin, Interactions with --Prefix and Destdir
Can Someone Explain the Shell Shock Bash Code
How to Move First Column to Last Column in Unix