if clause in AWK END block not working.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if clause in AWK END block not working.
# 1  
Old 04-21-2006
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 Smilie Everthing seem to work interms of the stats output, but if clause in the END block dosnt seem to work? any ideas would be greatly appreciated!

Kind Regards

Satnam

awk -F, -v invalid_rec_count=0 ' { if (NF!=field_count) {
invalid_rec_count+=1 ;
if (invalid_rec_count<=max_spool) {
print $1;
}
}
}
#END { printf "%-10s\t\n","Total Lines["NR"]" ; if (invalid_rec_count=5) { "App error" ; exit 1 ;} }
END { printf "%-10s\t\n%-10s\t\n","Total Lines["NR"]","Invalid["invalid_rec_count"]" ; if (invalid_rec_count=5) { exit 1 } }

' max_spool="$bad_file_max_spool" field_count="$FIELD_COUNT" $data_dir_and_file
# 2  
Old 04-21-2006
Please ignore. problem solved. My mistake!

Please ignore. problem solved. My mistake! Me being silly!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add a block of code at the end of a specific block

I need to search for a block with the starting pattern say "tabId": "table_1", and ending pattern say "]" and then add a few lines before "]" "block1":"block_111" "tabId": "table_1", "title":"My title" ..... .... }] how do I achieve it using awk and sed. Thanks, Lakshmi (3 Replies)
Discussion started by: Lakshmikumari
3 Replies

2. Shell Programming and Scripting

Define procedure in block END in awk

Hi :) Yo quisiera saber si se puede definir procedimientos dentro del bloque END. for example ... BEGIN {i=1} { if ($1 == $2) cadena = $3 } END { find_letter(cadena) } find_letter(cadena { ... } (3 Replies)
Discussion started by: solaris21
3 Replies

3. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

4. Shell Programming and Scripting

Use of Begin IF ,END IF END not working in the sql script

Hi I have written a script .The script runs properly if i write sql queries .But if i use PLSQL commands of BEGIN if end if , end ,then on running the script the comamds are getting printed on the prompt . Ex :temp.sql After connecting to the databse at the sql prompt i type... (1 Reply)
Discussion started by: isha_1
1 Replies

5. UNIX and Linux Applications

Print date at END clause of AWK

Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja. My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a... (4 Replies)
Discussion started by: fmeriles
4 Replies

6. Shell Programming and Scripting

The function of substr clause in awk command

Hello all, Please help me in letting me know the function of *substr* function in awk... actually i am new with this function i can play with awk but for this function needs your help in making me understand the correct way of using it. I am writting a code please advice regarding this... (4 Replies)
Discussion started by: jojo123
4 Replies

7. Shell Programming and Scripting

for loop not working - syntax error at line 6: `end of file' unexpected

I have a file called test.dat which contains a b I have written a shell script called test.sh for i in `cat test.dat` do echo $i done When i run this script using sh test.sh I get this message - test.sh: syntax error at line 6: `end of file' unexpected What is the... (3 Replies)
Discussion started by: debojyoty
3 Replies

8. Shell Programming and Scripting

having trouble with using if clause in AWK

The goal: I have a list of people in teams. The list looks something like this $1 = Job Position (marketing, IT, PR) $2 = Name $3 = Team Name $4 = Targeted member (somebody in field 2 targets somebody else) $5 = Employment Status (full time/part time/etc) The idea is to search through... (2 Replies)
Discussion started by: MaestroRage
2 Replies

9. Shell Programming and Scripting

array access in END block failure

Hi guys i am new to shell scripting. I wrote this script that simply searches a column value of file1 from file2. please look at the code below: awk ' FILENAME==ARGV { file_1_data=$0; next } FILENAME==ARGV { file_2_data=substr($3,1,12); next } END { ... (5 Replies)
Discussion started by: fahadaizaz
5 Replies

10. UNIX for Dummies Questions & Answers

Working out end time from start + elapsed

Hi, I'm writing a script and have become stuck trying to define a variable (COMP) by adding an elapsed time (ELAPSE e.g 00:55) to a start time (START e.g 23:50). Can anybody give me a solution as to how I can get a completion time in hh:mm from the variables above? thanks Richard (4 Replies)
Discussion started by: rik1551
4 Replies
Login or Register to Ask a Question