Help on awk and grep command to get the date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on awk and grep command to get the date
# 1  
Old 06-17-2013
Help on awk and grep command to get the date

Hi All

I need to get the date from a file.
my file a.out has the below data:
Code:
INFO : LM_36435 [Sun Jun 17 05:00:05 2013] : (10153|1400211776) 
Starting execution of workflow [w_.......] in folder [GL....] 
last saved by user [gli....].

The date here is Sun Jun 17 05:00:05 2013 ,which is the system date and keep on changing everyday.
So help me hoe can i get the specific value from the file and move to an xls file.

Thanks
Aliva

Last edited by vbe; 06-17-2013 at 05:12 AM.. Reason: please use code tags for code AND data...
# 2  
Old 06-17-2013
Code:
awk -F"[][]" '/INFO :/ {print $2}' file
Sun Jun 17 05:00:05 2013

# 3  
Old 06-17-2013
Guys i can explain u elaborately.
First i am using sed command to get the first line from a file and storing in a.out.
Again using sed to get the last line from the same file and storing in a.out
Now that my a.out file has below data:
Code:
INFO : LM_36435 [Sun Jun 17 05:00:05 2013] : (10153|1400211776) Starting execution of workflow [w......] in folder [GL....] last saved by user [g....].
INFO : LM_36318 [Sun Jun 17 05:00:16 2013] : (10153|1431681344) Workflow [w.....]: Execution succeeded.

I want to pick both the date and subtract the time.
please suggest on the same.
# 4  
Old 06-17-2013
Code:
cat logfile | perl -nle 'print $1 if /\[((Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2} \d{2,2}:\d{2,2}:\d{2,2} \d{4,4})\]/'

# 5  
Old 06-17-2013
I have used the below script to get the output:
Code:
cat test.sh | sed -n 1p >a.out
awk -F"[][]" '/INFO :/ {print $2}' a.out >a1.out
rm a.out
sed 's/^/var1=/g' a1.out >a.out
rm a1.out
cat test.sh | sed -n '$p' > a1.out
awk -F"[][]" '/INFO :/ {print $2}' a1.out >a2.out
rm a1.out
sed 's/^/var2=/g' a2.out >>a.out
rm a2.out

a.out file now contains two different date :
Code:
var1=Sun Jun 17 05:00:05 2013
var2=Sun Jun 17 05:00:16 2013

Now i need to find teh difference between these time stamp.
Please help me on teh same.
# 6  
Old 06-17-2013
Difference in seconds
Code:
diff=$(($(date -d "$var2" +%s) - $(date -d "$var1" +%s)))
echo $diff
11

# 7  
Old 06-17-2013
But i need to do for teh dates present in the file.
some think like cat a.out | getting the difference.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Date in awk command

Hello guys. i have problem to execute the: DT=$(date +"%Y%m%d"); command in awk script. i wrote this script: #bin/bash BEGIN{ FS="" DT=$(date +"%Y%m%d"); FullBackupValue=0; LevelBackupValue=0; ControlBackupValue=0; ArchBackupValue=0; } { if($1 == "full" &&... (4 Replies)
Discussion started by: Ymir
4 Replies

3. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

4. Shell Programming and Scripting

Help in using date command inside awk

Hi All, bash-3.2$ autorep -J BOX_NAME% -l0 | grep BOX_NAME| awk -f awkScript.awk sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file BOX_NAME SU 06/21/2013 03:44:03 06/21/2013 07:46:37 0 #My awkfile { ... (3 Replies)
Discussion started by: ddspark
3 Replies

5. Shell Programming and Scripting

awk - append date to output of a command

Hi all; I am running a script:/var/tmp/gcsw -ne | grep "State:2" | wc that gives me output like:80 480 6529 but i need this output as:2013-01-18 13:00 -> 80 480 6529 (1 Reply)
Discussion started by: gc_sw
1 Replies

6. Shell Programming and Scripting

awk command with date

hi, I have one file /home/user/file1 which entry is below cat /home/user/file1 /tmp/test1 /tmp/test2 /tmp/test3 now I want to create a new file with name /home/user/file2 with date as suffix after each entry. like cat /home/user/file2 /tmp/test1_`date "+%Y-%m-%d"`... (5 Replies)
Discussion started by: anshu ranjan
5 Replies

7. Shell Programming and Scripting

grep date with copy command

how can i copy only those files with creation date less then 24 hours. (1 Reply)
Discussion started by: Danish Shakil
1 Replies

8. Shell Programming and Scripting

Using awk with the date command and escape characters

I have a file that is a log file for web traffic. I would like to convert the timestamp in it to unix time or epoch time. I am using the date command in conjunction with awk to try to do this. Just myfile: 28/Aug/1995:00:00:38 1 /pub/atomicbk/catalog/home.gif 813 28/Aug/1995:00:00:38 1... (3 Replies)
Discussion started by: jontjioe
3 Replies

9. Shell Programming and Scripting

Show date/time with tail|grep command

Hi, I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time: tail -F catalina.out | sed "s/^/`date `/" | egrep ... (6 Replies)
Discussion started by: julugu
6 Replies

10. Shell Programming and Scripting

Using awk and current date command

I am running a command to extract data from a database which has different text and dates (ex. 01/03/07, 05/29/08, 06/05/08). Once the file is created I need to grep for all the text with a current date then redirect the sorted data to another file then email the file out. Here is what I have right... (2 Replies)
Discussion started by: wereyou
2 Replies
Login or Register to Ask a Question