Split A File Into 2 Files

i WANT TO SPLIT A FILE WHICH HAS 250 COLUMNS. and the delimiter is '|'. So , can somebody help me with the command i have to use to split the file into two files.

thanks

Which columns are going into which output files, in what format and in which column order?

Are these two posts related ?

http://www.unix.com/shell-programming-scripting/44831-have-file-300-columns.html

cat FILE | awk -F\| '{for(i=1;i<125;i++) printf "%s ",$i; printf"\n"}' > firs125col.log
cat FILE | awk -F\| '{for(i=125;i<251;i++) printf "%s ",$i; printf"\n"}' > second125col.log

have a nice day :slight_smile:

UUOC,

use it like,

awk '{}' filename > outputfilename

Yes, Those two posts are related. And i still didnt understand . Can anyone explain in clear. Or can anyone give me a clear code
Thanks

The following code split the inputfile (with '|' as field separator FS) into two files first125cols.dat and last125cols.dat (with '|' as field separator OFS).

awk -v FS='|'  -v OFS='|' '
{
   # Write first 125 cols

   for (field=1; (field<=125 && field<=NF); field++)
      line = line (field>1 ? OFS : "") $field;
   print line > "first125cols.dat"

   # Write last 125 cols

   for (field=125; (field<=255 && field<=NF); field++)
      line = line (field>1 ? OFS : "") $field;
   print line > "last125cols.dat"
}
' inputfile

I am very sorry as i am new to scripting. Can you please help me with the starting of the code.
Like the whole script file so that based on that i can execute and understand the scripting. Sorry for asking you so detailed answer. And please asssume my input filename is input.dat. Based on this please help me in a neat script file.

Thanks in advance