The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
.
google unix.com



UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
print all dates 100 days from current date pavan_test UNIX for Dummies Questions & Answers 5 07-20-2009 09:25 PM
awk to print current date? philipz UNIX for Dummies Questions & Answers 3 09-02-2008 03:58 PM
how to print date using ftp commands kittusri9 Shell Programming and Scripting 3 05-07-2008 03:48 AM
how to print the date and time separately??? jisha Shell Programming and Scripting 8 01-16-2008 06:23 AM
Need to print file names in a certain date range using ls Shamwari UNIX for Dummies Questions & Answers 2 10-08-2001 07:14 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
fmeriles fmeriles is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 3
Print date at END clause of AWK

Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja.

My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a file.
Some thing like:

BEGIN{
"date" |getline;
print >>TestLog.log
}

These lines works "sweetly" at the BEGIN clause... but it doesn't at the END clause.
I'm working on a HP-UX (unknow version )

I know that this is not actually a big challenge (jajaja) but I googled as much I could without results.

How could I log the end of the AWK script execution?

Thanks matrixmadhan for you support

F
  #2 (permalink)  
Old 2 Weeks Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Use getline var instead of getline only.

Code:
$ awk < /dev/null 'BEGIN {
  if (!("date" | getline dt))
    print "Error getting date"
  }
END {
  print "date is:", dt
  }'
date is: Fri Nov  6 12:29:53 MET 2009
  #3 (permalink)  
Old 2 Weeks Ago
fmeriles fmeriles is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 3
Quote:
Originally Posted by radoulov View Post
Use getline var instead of getline only.

Code:
$ awk < /dev/null 'BEGIN {
  if (!("date" | getline dt))
    print "Error getting date"
  }
END {
  print "date is:", dt
  }'
date is: Fri Nov  6 12:29:53 MET 2009
Hi dude, thanks for your reply!

Actually, works like you said, but you are storing the date at the beging of the script execution. I need the date/time when the script ends.

Thanks for your reply

F
  #4 (permalink)  
Old 2 Weeks Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by fmeriles View Post
... but you are storing the date at the beging of the script execution. I need the date/time when the script ends.
[...]
You can use something like this:

Code:
awk <<< 1  'BEGIN {
  printf "start: "; system("date")
  }
system("sleep 3")
END {
  printf "end: "; system("date") 
  }'

Code:
zsh-4.3.10[sysadmin]% awk <<< 1  'BEGIN {
  printf "start: "; system("date")
  }
system("sleep 3")
END {
  printf "end: "; system("date")
  }'  
start: Fri Nov  6 15:38:53     2009
end: Fri Nov  6 15:38:56     2009


---------- Post updated at 03:47 PM ---------- Previous update was at 03:31 PM ----------

Actually, you just need to close the external command:

Code:
awk <<< 1  'BEGIN {
  "date" | getline dt
  close("date")
  print "start:", dt
  }
system("sleep 3")
END {
  "date" | getline dt
  close("date")
  print "end:", dt 
  }'

Like this:

Code:
zsh-4.3.10[sysadmin]% awk <<< 1  'BEGIN {
  "date" | getline dt
  close("date")
  print "start:", dt
  }
system("sleep 3")
END {
  "date" | getline dt
  close("date")
  print "end:", dt
  }' 
start: Fri Nov  6 15:47:23     2009
end: Fri Nov  6 15:47:27     2009

Last edited by radoulov; 2 Weeks Ago at 10:39 AM..
  #5 (permalink)  
Old 2 Weeks Ago
fmeriles fmeriles is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 3
Quote:
Originally Posted by radoulov View Post
You can use something like this:

Code:
awk <<< 1  'BEGIN {
  printf "start: "; system("date")
  }
system("sleep 3")
END {
  printf "end: "; system("date") 
  }'

Code:
zsh-4.3.10[sysadmin]% awk <<< 1  'BEGIN {
  printf "start: "; system("date")
  }
system("sleep 3")
END {
  printf "end: "; system("date")
  }'  
start: Fri Nov  6 15:38:53     2009
end: Fri Nov  6 15:38:56     2009
---------- Post updated at 03:47 PM ---------- Previous update was at 03:31 PM ----------

Actually, you just need to close the external command:

Code:
awk <<< 1  'BEGIN {
  "date" | getline dt
  close("date")
  print "start:", dt
  }
system("sleep 3")
END {
  "date" | getline dt
  close("date")
  print "end:", dt 
  }'

Like this:

Code:
zsh-4.3.10[sysadmin]% awk <<< 1  'BEGIN {
  "date" | getline dt
  close("date")
  print "start:", dt
  }
system("sleep 3")
END {
  "date" | getline dt
  close("date")
  print "end:", dt
  }' 
start: Fri Nov  6 15:47:23     2009
end: Fri Nov  6 15:47:27     2009

It works! Thank you very much dude!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0