The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > HP-UX
Google UNIX.COM


HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare 2 files and output result in pop up window hongsh UNIX for Dummies Questions & Answers 2 05-23-2008 06:50 AM
Need to Output result to a non-delimitted file cosec Shell Programming and Scripting 1 04-07-2008 01:51 AM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 06:43 PM
output result (period -1) happyv Shell Programming and Scripting 4 05-18-2007 03:11 AM
any possible to run sql result and output to file happyv Shell Programming and Scripting 7 03-02-2007 09:07 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-27-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print.

Code:
 .... | awk '{print $0}'
I would like it to print the date right before $0, so something like (this doesn't work though)

Code:
 .... | awk '{print date $0}'
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-27-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,923
Code:
... | awk '{ "date" | getline date; print date " " $0 }'
Querying the date again and again for each line is pretty wasteful, though. Perhaps you want to do it in a BEGIN block, or something like

Code:
... | awk -v date="`date`" '{ print date " " $0 }'
Really old classical awk might not have all the required facilities; try nawk or mawk or gawk if your plain awk won't do. On HP-UX in particular, you may find that the xpg4 awk is more modern than the plain /usr/bin/awk. Searching this forum suggests that setting the environment variable UNIX95=1 might get you that.

You have very clueful questions, keep it up! (-:

Last edited by era; 04-27-2008 at 05:37 AM. Reason: UNIX95=1 tip
Reply With Quote
  #3 (permalink)  
Old 04-27-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
That last one you posted works, but its static. The output of date never changes. Is there a way to make it dynamically call date every time it prints?

Thanks
Reply With Quote
  #4 (permalink)  
Old 04-27-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,923
Avoiding that was kind of the point. Try to find an awk which is new enough to do the first.
Reply With Quote
  #5 (permalink)  
Old 04-27-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 863
Here is one way of doing what you want:

Code:
{
   "date +%T" | getline cur_date; print cur_date, $0
}
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0