I have requirement that I need to split my input file into two files based on a search pattern "abc"
For eg. my input file has below content
abc
defgh
zyx
I need file 1 with
abc
and file2 with
defgh
zyx
I can use grep command to acheive this. But with grep I need to scan the input file twice to get the desired output. Also with huge files grep just hangs the system.
Can you please help me if I can use NAWK for this requirement?
Reading a file twice may not be too bad since grep is very efficient. On the other hand, processing it with "print > file" in awk will not be ideal since awk have to find which file to write and flush the file for each record (even though it only read the file once). I am sure there are other more efficient ways.