passing coloumn value to system function in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers passing coloumn value to system function in awk
# 1  
Old 07-07-2011
Question passing coloumn value to system function in awk

Hi all,

I have a file which contain data like
Code:
1|2009-12-12
2|2010-02-28
3|2009-02-29

i have to validate that second coloumn have proper date

i tried like

Code:
awk -F "|" ' !system("touch -d $2 file1 2> /dev/null" ) '

but its not printing any thing

but when i try using hard coded value it works
Code:
 awk 'BEGIN{if(!system("touch -d 2009-12-23 file1 2> /dev/null")) print "okay"; else print "not valid"}'
okay
 
 awk 'BEGIN{if(!system("touch -d 2009-02-29 file1 2> /dev/null")) print "okay"; else print "not valid"}'
 
not valid

what i am doing wrong ? SmilieSmilie

Thanks in advance
# 2  
Old 07-07-2011
Try:
Code:
awk -F "|" ' !system("touch -d "$2" file1 2> /dev/null" ) '

# 3  
Old 07-07-2011
Thanks it worked Smilie

i missed the quoted Smilie

i was wonderdering i am passing parameter wrong way
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable value in a function to be used by another function

Hello All, I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and put the variables in " ". Is there another way I can do this? Thank you in advance. readtasklist() { while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies

2. UNIX for Dummies Questions & Answers

Passing Input To Function

May i please know why is it printing the script name for $0 when i pass those parameters to function. #!/bin/bash -x usage() { echo "In Usage Function" echo $0 echo $1 echo $2 } echo "printing first time" echo $0 echo $1 echo $2 usage $0 $1 $2 Output: (2 Replies)
Discussion started by: Ariean
2 Replies

3. Shell Programming and Scripting

System function in awk

Hello Friends, I have written a script like below, I aimed to move some CDR files (call data record) whose the last field is "1" (NF=1 ) from a spesific directory to a new directory Field Seperator is pipe. If the directory does not exitst i should create it. I will give the script two... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

Passing alias to a function

The objective of this function is to validate the file full path. cat /dev/null > crontab_NOTEXISTS.txt function File_Existence # Accepts 1 parameter { file_name="$(echo $1)" echo "${file_name}" && break || echo "$file_name NOT FOUND" >> crontab_NOTEXISTS.txt } while read file_name... (7 Replies)
Discussion started by: aimy
7 Replies

5. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

6. Shell Programming and Scripting

Passing argument to system call in awk script

So, I have this script. It reads a CSV file that has a mixture of object names with IP addresses (parsing out that part I have working), and object names which have a DNS name. I want to be able to run a "dig +short" based off of the name given to me in the line of the awk script, and then deal... (6 Replies)
Discussion started by: mikesimone
6 Replies

7. Shell Programming and Scripting

How to use system function in awk

Could any one tell me how to use the system function in awk? I want to use it to print the system date. I have been trying like this : yes |head -1|awk '{ system("date")}' When I execute the above it always returns back to the prompt. Your help would be much appreciated. regards,... (3 Replies)
Discussion started by: srikanth_ksv
3 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. Shell Programming and Scripting

shell function, system, awk

Hi all, I am calling a shell function within awk using system. I am struggling to get my expected output: #!/bin/sh set -o nounset BEG=44 END=55 shfun() { echo "1|2|3" } export -f shfun typeset -F > /dev/null awk 'BEGIN {OFS="|"; print "'"$BEG"'",system( "shfun"... (5 Replies)
Discussion started by: jkl_jkl
5 Replies

10. Shell Programming and Scripting

Passing more than one argument in a function

Hi All, Calling a function with one argument and storing the return value in a shell script is as below:( so far I know) value="`fun_1 "argument1"`" Its working perfectly for me. Can u help me with passing more than one argument and storing the return value Thnaks in advance JS (1 Reply)
Discussion started by: jisha
1 Replies
Login or Register to Ask a Question