The following code will split the infile into multiple files. However, I need it to insert the same first 3 lines from the original input file into each splitted file. How do I modify my script below to do so:
print -n "Enter file name to split? " ; read infile
if [ -z "$infile" ]
then
echo "Invalid file name entered ..."
exit 255
fi
print -n "Enter Number of files to split it into? " ; read numf
if echo $numf | egrep -q '^[2-9]{1}$'; then
echo
else
echo "Invalid number <$numf> entered. Entry must be numeric and 1 digits in length and between 2 and 9 ..."
exit 255
fi
echo "Splitting file $infile into $numf files ....."
sleep 2
awk '{a[NR]=$0}END{for(i=1;i<=NR;i++)print a > "'split.$infile.'" 1+int(n*((i-1)/NR))}' n=$numf $infile
echo "Done...."
Thank you. I ran it using your new awk. Then I combined them using cat file1 ..etc > combined-file to see if missed any entries after removing the first 3 lines from file 2 ..etc. Then i did a diff combined-file <original input combine file before the split>, I get a discrapancy I think due to some hidden format characters changes in the new split file. When I used my version of the awk i get none. How can fix it?
Here is a sample of discrapancies due to some formatting issue of the new AWK:
3255a3096,3097 <- Not in the files, but shows when doing a diff
> |9787771000|
> |9787772000|
3256a3099,3100 <-- causing a diff !!
> |9787804000|
Thanks
---------- Post updated at 04:05 PM ---------- Previous update was at 03:03 PM ----------