awk - writing matching pattern to a new file and deleting it from the current file

Hello ,

I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file.

Can someone tell me how i could go about doing this?

The master file is file.out and the file that i am trying to write the lines with null records is called test_exc

I am trying the below code without joy

function SX_file_exc {
        nawk -F, '{
                if( $1 == "" )
                {
                        {next}{print}
                }
                if( $8 == "" )
                {
                        {next}{print}
                }
                if( $13 == "" )
                {
                        {next}{print}
                }
        }' OFS=, file.out >> test_exc
        return
}

Hi, try:

awk -F, '$1=="" || $3=="" || $8=="" {print>f; next}1' f=test_exc file.out > filenew.out
1 Like

Cheers.. It worked a charm