I am not sure how to achieve the function call in the nawk
command. I have given the scope what i want want from the input and output. The function should validate the column 3 and return true or false. If the column satisfies the condition then it should go to good file; if not go to bad file. Can you help me in modifying the nawk
command to achieve my functionality?
I know we can achieve the length validation in single statement but my validate function is just the sample code. I want to achieve more that length check in the validate function.
input.txt:
1 | I | 123 | KK
3 | U | 3456 | JJ
6 | B | 241 | YH
outputgood.txt:
3 | U | 3456 | JJ
outputbad.txt:
1 | I | 123 | KK
6 | B | 241 | YH
Script:
#!/bin/sh
#function validation
function validate(){
in = $1
if length(in) > 3
return true
else
return false
}
nawk -F '|' 'function validate($3){print}' input.txt > outputgood.txt