I am trying to split a file using AWK on a specific delimiter. The awk code is as follows:
awk '/SEPARATOR/{n++}{print > "part" n ".txt" }' in.txt
this code works fine on my linux systems. But when I run the exact same code on Mac OS X, I get the following error:
awk: syntax error at source line 1
context is
/SEPARATOR/{n++}{print > "part" >>> n <<< ".txt" }
awk: illegal statement at source line 1
I guess this is some kind of difference between the awk that comes with OS X and mawk from Linux. Removing the string concatenation in the printout causes the awk program to work on both platforms, but I would prefer to keep the prefix and surfix. How to write an awk program that splits a file on a separator into several numbered parts and works on both platforms?
pehrs source
share