Exclude the header row while splitting the file

Hi All,
i have script like ...

 "TYPE_ID" "ID"    "LIST_ID"
"18"    "52010" "1059"
"18"    "52010" "1059"
"18"    "52010" "1059"
"18"    "52010" "1059"  

i am using the below code it's not taking the header row.

 awk -F"\t" -v file=test1.txt -v file1=test2.txt ' {
    if( ($3=="\"1010\"") || ($3=="\"17003\"") ) { print $0 >> file }
     else
    { if( ($3=="\"1059\"") || ($3=="\"14958\"") ) { print $0 >file1 } } } ' test.txt
 

required output should be with header row if any file creation. My code not taking the header row.

Thanks,

 awk -F"\t" -v file=test1.txt -v file1=test2.txt ' { if(NR==1){print;next} else
    if( ($3=="\"1010\"") || ($3=="\"17003\"") ) { print $0 >> file }
     else
    { if( ($3=="\"1059\"") || ($3=="\"14958\"") ) { print $0 >file1 } } } ' test.txt

Thanks ...
if i use this data not coming header row in the two files.

"TYPE_ID"       "ID"    "LIST_ID"
"18"    "52010" "1059"
"18"    "52010" "1010"
"18"    "52010" "1059"
"18"    "52010" "1059"
 
awk -F"\t" -v file=test1.txt -v file1=test2.txt ' { if(NR==1){print $0>file;print $0>file1;next} else
    if( ($3=="\"1010\"") || ($3=="\"17003\"") ) { print $0 >> file }
     else
    { if( ($3=="\"1059\"") || ($3=="\"14958\"") ) { print $0 >file1 } } } ' test.txt

Thanks,if we use below data test1.txt with header created. but test2.txt only creating the header without data this one i don't want because there no data for this one.

 "TYPE_ID"       "ID"    "LIST_ID"
"18"    "52010" "1010"
"18"    "52010" "1010"
"18"    "52010" "1010"
"18"    "52010" "1010" 

Try this. This code uses hardcoded header values in case data exists for the particular criteria.

awk  -v file=test1.txt -v file1=test2.txt  '
    {if( ($3=="\"1010\"") || ($3=="\"17003\"") ) 
	{if (H==0) {print "\"TYPE_ID\"\t\"ID\"\t\"LIST_ID\"" >file; print $0 > file; H=1} else { print $0 > file} }
     else
      { if( ($3=="\"1059\"") || ($3=="\"14958\"") ) 
	{ if (H1==0) {print "\"TYPE_ID\"\t\"ID\"\t\"LIST_ID\"" >file1; print $0 > file1; H1=1} else { print $0 > file1} }
      } 
    } ' test.txt

Using the header from the 1st line of the input file (after changing the sample input by replacing all sequences of spaces with a tab), the following seems to do what you want:

awk -F"\t" -v file=test1.txt -v file1=test2.txt '
NR == 1 {
        H = $0
        next
}
{       if($3 == "\"1010\"" || $3 == "\"17003\"") {
                if(! HC++) print H > file
                print > file
        } else  if($3 == "\"1059\"" || $3 == "\"14958\"") {
                if(! H1C++) print H > file1
                print > file1
        }
}' test.txt

only producing test2.txt with the sample input in test.txt shown in the 1st message in this thread.

Awesome @Don and good helping guyes