Sponsored Content
Special Forums UNIX and Linux Applications Print date at END clause of AWK Post 302369053 by fmeriles on Friday 6th of November 2009 10:09:46 AM
Old 11-06-2009
Quote:
Originally Posted by radoulov
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!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

if clause in AWK END block not working.

Hello all... I have a slight problem in my awk script... I have a script which checks a csv file and keeps a count of any invalid records and then if it finds any, exits with a code of 1. problem is it dosnt seem to work properly :rolleyes: Everthing seem to work interms of the stats output,... (1 Reply)
Discussion started by: satnamx
1 Replies

2. UNIX for Dummies Questions & Answers

awk to print current date?

List, I want to print the first line of my text file (say "me you"), preceded by the current date/time. Something like (pseudo code): awk '{print date,$1}' I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious... (3 Replies)
Discussion started by: philipz
3 Replies

3. Shell Programming and Scripting

using awk to print date

i want to use awk to print the first,second and add date as third column in a file awk -F"|" ' { print $1,$2,current date }' tom.unl >> top.txt how can i achieve this,i need the comma's to seperate them and finally print current date and time as the third. i want output like... (5 Replies)
Discussion started by: tomjones
5 Replies

4. Shell Programming and Scripting

How to Print from matching word to end using awk

Team, Could some one help me in Printing from matching word to end using awk For ex: Input: I am tester for now I am tester yesterday I am tester tomorrow O/p tester for now tester yesterday tester tomorrow i.e Starting from tester till end of sentence (5 Replies)
Discussion started by: mallak
5 Replies

5. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

6. Shell Programming and Scripting

strange: sed and awk print at end instead of begin of line

Hi! I have a strange behaviour from sed and awk, but I'm not sure, if I'm doing something wrong: I have a list of words, where I want to add the following string at the end of each line: \;\;\;\;0\;1 I try like this: $ cat myfile | awk '{if ( $0 != "" ) print $0"\;\;\;\;0\;1"}' Result:... (5 Replies)
Discussion started by: regisl67
5 Replies

7. Shell Programming and Scripting

Find and print specific date with awk

hi all I would like to help me find the problem with this script to find and print to the screen a specific date of a log file that I have on my server, the date it is received as the first argument in the script $ 1 Here I show you a few lines that made ​​the idea of ​​my log file: ****... (4 Replies)
Discussion started by: gilmore666
4 Replies

8. Shell Programming and Scripting

awk one liner to print to end of line

Given: 1,2,whatever,a,940,sot how can i print from one particular field to the end of line? awk -F"," '{print $2 - endofline}' the delimiter just happens to be a comma "," in this case. in other cases, it could be hypens: 1---2---whatever---a---940---sot (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

Print start date to end date, given $1 & $2 in ksh

Dear all, I have an user passing 2 parameter 31/03/2015 and 02/04/2015 to a ksh script. How to print the start date to end date. Expected output is : 31/03/2015 01/04/2015 02/04/2015 Note : 1. Im using aix and ksh 2. I have tried to convert the given input into a date, didnt... (0 Replies)
Discussion started by: mr.rajaravi
0 Replies

10. Shell Programming and Scripting

awk to print the string between 3rd and 4th backslashs to end of line

im trying to get awk to print the string between 3rd and 4th backslashs to end of line test could be any word this http://example.com/test/ >to this http://example.com/test/ > testalso the other way round insert string at end of line... (13 Replies)
Discussion started by: bob123
13 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 06:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy