I have what a think is a simple question but I'm just a beginner in scripting. I'm my unix command line I run a date command that returns the following:
Wed Apr 3 10:39:30 EDT 2013
How do I awk out the "10" only in awk? Or is awk the way to do it or is there a better way?
Yoda
April 3, 2013, 11:14am
2
You can simply run date
with format control to get hour:
date +%H
1 Like
echo 'Wed Apr 3 10:39:30 EDT 2013' | awk -F'[ :]' '{print $4}'
date +%H
1 Like
Thanks. How can I get it to recognize the hour variable?
hour=date +%H -d "1 hour ago"
i=test.`date +%Y%m%d`-$hour3101.txt
Yoda
April 3, 2013, 11:38am
6
Use command substitution $(..)
hour=$(date +%H -d "1 hour ago")
1 Like
hour=$(date +%H -d "1 hour ago")
i=$(grep Multiple test.`date +%Y%m%d`-$hour3101.txt)
I'm still missing something. I'm getting the following error:
grep: test.20130403-.txt: No such file or directory..
So it's not picking up the hour variable.
Yoda
April 3, 2013, 12:06pm
8
i=$( grep Multiple "test.`date +%Y%m%d`-${hour}3101.txt" )
The curly brace form is unambiguous as the variable name is clearly delimited.
1 Like
Jotne
April 3, 2013, 1:47pm
9
Would it not it be better to remove the back ticks complete?
i=$( grep Multiple "test.$( date +%Y%m%d )-${hour}3101.txt" )