Sysdate inside awk print statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sysdate inside awk print statement
# 1  
Old 07-08-2011
Sysdate inside awk print statement

Hi,

I am using awk statement to extract data from a file and write a new file with certain columns rearranged and few hard coded values added to new file.

Now i need to add a column with sysdate. can i do that inside the awk print statement?

Now:
Code:
nawk ' /^3/ BEGIN {FS=","} {print("5",$1,$28,"$27",$26)}' $FILENAME >> newfile

Expected: sydate to be included, at the same time i have planned to use printf to make sure for proper padding of spaces

Code:
nawk ' /^3/ BEGIN {FS=","} {print("5","syadate"$1,$28,"$27",$26)}' $FILENAME >> newfile

Help me out with a few suggestions

Last edited by Franklin52; 07-08-2011 at 03:44 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-08-2011
See if you can use this inside your code :
Code:
awk -v sysdate=$(date "+%Y%d%m") ' { print sysdate } '

# 3  
Old 07-08-2011
gawk has the function called strftime

Code:
 
gawk 'BEGIN{print strftime("%y_%m_%d_%H_%M_%S")}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk statement piped inside sed

Hello folks, I have multiple occurrences of the pattern: ).: where is any digit, in various text context but the pattern is unique as this regex. And I need to turn this decimal fraction into an integer (corresponding percent value: the range of 0-100). What I'm doing is: cat... (1 Reply)
Discussion started by: roussine
1 Replies

2. Shell Programming and Scripting

Command in inside awk statement

Hello can you please help me with below script which is meant to delete clients from multiple netbackup policies I want to run a command insdie awk statement apparelnlty this script is not working for me for i in $( cat clients_list) do bppllist -byclient $i | awk... (6 Replies)
Discussion started by: Sara_84
6 Replies

3. Shell Programming and Scripting

For loop inside awk to read and print contents of files

Hello, I have a set of files Xfile0001 - Xfile0021, and the content of this files (one at a time) needs to be printed between some line (lines start with word "Generated") that I am extracting from another file called file7.txt and all the output goes into output.txt. First I tried creating a for... (5 Replies)
Discussion started by: jaldo0805
5 Replies

4. Shell Programming and Scripting

Explanation of print statement - awk

Hi, i'm just after a simple explanation of how the following awk oneliner works. gawk -F"," '{for(i=m;i<=n;i++)printf "%s" OFS,$i; print x}' m=1 n=70 OFS=, input.csv > output.csv In particular i'm trying to understand how the two print statements work? How is the "x" variable being assigned... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

5. Shell Programming and Scripting

use awk print statement for two files

Hello, is there a way to use the awk print statement on two files at once? I would like to take two columns from one file, and one column from another file and print them as consecutive columns to a third file. Seems simple...as in: file 1 1 a 2 b 3 c 4 d 5 e file 2 1 t 2 u... (3 Replies)
Discussion started by: HugoHuhn
3 Replies

6. Shell Programming and Scripting

Can't print multiple lines inside awk :(

Hi Friends, I have small issue with following code snippet. I am trying call one function inside awk in which the function inturn will echo few lines. However when i ran script its throwing an error saying "nawk: syntax error at source line 1". #!/bin/sh eval input=$@ while read... (3 Replies)
Discussion started by: Shahul
3 Replies

7. Shell Programming and Scripting

awk inside another awk statement

hi all, i have two files 1) a.txt one two three 2) abc "one" = 10 pqr "three" = 20 345 "two" = 0 this is what i want in third file (3 Replies)
Discussion started by: shishirkotkar
3 Replies

8. Shell Programming and Scripting

Print to 2 files in awk if statement

Hi all, I have some code like this awk -F, '{ if ($1==3) print $2 > "output_file" print "1" > "new_file" }' "input_file" When I check output_file this has the correct values in it. However the new_file has 1 in it for every line in the input_file. If the input file has 20 lins then... (2 Replies)
Discussion started by: Donkey25
2 Replies

9. Shell Programming and Scripting

print argv inside awk

mode=$1 psg telnetd | awk current=`date +%M`'{ printf ("mode is %s",mode) printf ("mode is %s",ARGV) }' at command prompt when i run the script along with the argument i get only-- 'mode is ' argument is not printed.(If the argument is... (3 Replies)
Discussion started by: Anteus
3 Replies

10. Shell Programming and Scripting

variable inside awk '{print $c}'

i'm trying to do this (in bash darwin); echo "give me some words: " read a c=2 # this is get by other ways echo $a | awk '{print $c}' # i want to print the column given # by de $c variable if there is someone understand what i pretend... (3 Replies)
Discussion started by: Tártaro
3 Replies
Login or Register to Ask a Question