If it is empty in column 5

Hi,
I have a file with many columns. If it is empty in column 5 I want it to transfer the entire row into a new file. If there is a word (any word) in column 5 then I want it to be transfered into another separate file.

e.g.
input

1 2 3 4 5
2 3 4 5   

File 1

1 2 3 4 5

File 2

2 3 4 5  

thanks

Try:

awk 'NF==5{print > "file1"}NF<5{print > "file2"}' file

Hi the code does not output any files.

What is your OS and version? Are the fields/columns in the input file space separated?

they are tab separated. I have osx 10.6.8

I don't see anything wrong with the program.

How exactly are you running it? Show exactly what you did, word for word, letter for letter, keystroke for keystroke.

I used awk before so the computer can certainly handle it. Here is what I inputted (basically copy and paste)

awk 'NF==12{print > "10_z_trans.txt"} NF<12{print > "10_z_nontrans.txt"}' 10_z.txt

I don't see the files "10_z_trans.txt" and "10_z_nontrans.txt"

note: I am trying for column 12

Could it be that the empty field is not the last field?

awk -F'\t' -v f=file1 '$5==""{print>f; next}1' infile > file2
1 Like

Line endings

[mute@geek ~]$ file input
input: ASCII text, with CR line terminators
[mute@geek ~]$ awk '{print NR,NF "::\t" $0}' input
1 9::   2       3       4       4       5
[mute@geek ~]$ awk '{print NR,NF "::\t" $0}' RS="\r" input
1 5::   1       2       3       4       5
2 4::   1       2       3       4

yes it worked... something weird was wrong but you guys fixed it. thank you all

Kyle