Parameter not accepting in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parameter not accepting in awk
# 1  
Old 06-13-2013
Parameter not accepting in awk

In below script parameterwhich i am passing to awk function is not working.Not sure why its not accepting parameter.Please tell me how to pass parameter to the awk function.Please check the below script.
Code:
#!/bin/ksh
 
dummy_file=/etlapps/dev/data/sub_servicer_data/ScriptLogs/emp.txt
fields=5
column='$1'
datatype=[0-9.]
length=2
awk -FÇ '
NR==1{next}
{f="ok"}
$1!~/^/$datatype{1,$length}$/{f="s-err"}
$2!~/^[a-zA-Z0-9]{1,20}$/{f="n-err"}
$3!~/^[0-9.]{1,10}$/{f="p-err"}
$4!~/^[a-zA-Z0-9]{0,20}$/{f="de-err"}
$5!~/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/{f="da-err"}
{print f,$0}
' $dummy_file

emp.txt(source file)
Code:
snoÇnameÇphonenoÇdeptÇjoineddate
1.ÇvivekÇ0861ÇCSEÇ2013-05-29 00:00:00
2ÇdineshÇ1234.56ÇECEÇ2013-05-29 00:00:00
3ÇsaiÇ568ÇÇ2013-05-29 00:00:00
4ÇsridarÇ123ÇITÇ2013-05-29 00:00:00


Last edited by Franklin52; 06-13-2013 at 03:21 AM.. Reason: fixed code tags
# 2  
Old 06-13-2013
Why not use post you already have:
https://www.unix.com/shell-programmin...-checking.html
# 3  
Old 06-13-2013
in previous post we directly defined values,in above scenario i want pass value as parameters.Parameters are not accepting in 1st line of awk function.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Does awk have parameter substitution?

Can I specify a default value to a variable in AWK like BASH in one statement using parameter substitution? BASH example: argument=${$1-"default if empty"} (BASH) I know I can do: argument=$1; sub ( "^$", "default if empty", argument) (AWK) Mike (13 Replies)
Discussion started by: Michael Stora
13 Replies

2. Shell Programming and Scripting

Loop over awk or passing parameter

I wrote this script which works well when I manually input 55518622 and 1 but I need this script to be generic and loop over the following table awk '$4>(55518622-500000) && $4<(55518622+500000)' chr1_GEN2bim | awk 'BEGIN {min=1000000000; max=0;}; {\ if($4<min && $4 != "") min = $4; if($4>max... (8 Replies)
Discussion started by: fat
8 Replies

3. Shell Programming and Scripting

awk: replace with script parameter

Hi var=0001 I want to replace 2nd field of file with variable var in file sample.txt Please suggest with awk. dont want to use awk -v option. pseudo code : something like this. var=0001 awk '{ 12193 /var } {print $0 }' sample.txt (2 Replies)
Discussion started by: theshashi
2 Replies

4. Shell Programming and Scripting

Passing a parameter to AWK

Hi All, I am trying to pass a parameter to AWK on my KSH shell prompt as below. var1=2 echo $var1 awk -v var2=${var1} '{print var2}' testfile.txt I am passing the input file (testfile) to awk to get some o/p. It is having 10 records. When I run AWK, it is throwing the following errors... (1 Reply)
Discussion started by: Raamc
1 Replies

5. Shell Programming and Scripting

awk pass $LOGDIR parameter

hi guys i need your help , i wrote one script which is as below #!/bin/ksh ########################################################### LOGDIR=/export/home/xyz/logs EMAILFile=$LOGDIR/xxs_email.log BOX=$(uname -a | awk '{print $2}') awk '{if ($4 >= 30) {print $1 " " $3 " HAS LAG of "... (1 Reply)
Discussion started by: tapia
1 Replies

6. Shell Programming and Scripting

Parameter to AWK

Hi, I need help with AWK. Here is the issue that i'm facing. I have a variable in KSH script set as below. user_text="first second third fourth" My Requirement is to print 'first', 'second', 'third' or 'fourth' based on setting a variable Example 1 user_text="first second third... (17 Replies)
Discussion started by: sacguy08
17 Replies

7. Shell Programming and Scripting

using awk != parameter

Hi all, I am having the below file log.txt 1 aaa 111 @@@ 2 bbb 222 ### 14 ccc 333 $$$ using awk '$1!=1 || $1!=14 {print $1" " $2}' log.txt gets the below output 1 aaa 2 bbb 14 ccc (4 Replies)
Discussion started by: karthikn7974
4 Replies

8. Shell Programming and Scripting

awk parameter

How to pass a parameter in system function e.g system(script parameter) i want to run a shell script along with a parameter (5 Replies)
Discussion started by: alokmits
5 Replies

9. Shell Programming and Scripting

awk/input parameter

Hi, My script takes in one input parameter($1-email id) on the command line... The script contains something like this... awk '$1 == 400' abc.log >def.log mail -s subject $1 <def.log abc.log looks something like this... 300 222 330 123 445 400 098 890 727 663 How do i make the... (3 Replies)
Discussion started by: wannalearn
3 Replies

10. UNIX for Dummies Questions & Answers

PASS parameter to AWK

Hi, Can i pass a parameter(not a file name) as a parameter to a awk program? eg; $awk -f test 1 2 3 here test is the filename...and 1,2,3 are the i/p parameters? thank you:-) (2 Replies)
Discussion started by: unisam
2 Replies
Login or Register to Ask a Question