Splitting a file based on negative and positive numbers

I have a file that is pipe delimited and in Column F they have number values, both positive and negative. I need to take the one file I am starting with and split it into two separate files based on negative and positive numbers. What is the command to do so? And then I need to also transfer each of those files with 2 separate names to an SFTP server. I was trying something with an awk command, but I was told that using the split command might make this easier. Below is what I started with. Any help would be appreciated.

awk '{if($9~/\-/){print $0>"file1.txt"}else{print $0>"file2.txt"}}

Column F is field number 6 not 9.

awk -F "[ |]" -v v="F" '
NR==1           {for(i=1; i <= NF; i++) if (v == $i) break
                 print > "file1.txt"}
$i ~ "-"        {print > "file1.txt"; next}
                {print > "file2.txt"}
                ' file

Set a field separator!
Pipe delimited: -F"|" or BEGIN {FS="|"}
Then your initial code will work.
The previous post sets a pipe or space as the FS. (And it determines a column named F in the first line.)

1 Like

Some input and desired output samples might help.
I don't see the split nor the csplit tool to distribute lines to different target files based on a single field's contents. Try instead

awk -F"|" '{print > ($6<0?"NEG.TXT":"POS.TXT")}' file

If you don't want the sixth field to be the selector but the non-predetermined field labeled "F", use nezabudka's proposal to determine the relevant field number. Make sure there's only one field labeled "F"!