I have scenario where i want to split on every 5 records into new file Not getting how to start with this approach where i need to create split file dynamically
For example below is data in file :
Which contain 11 records , The script should split it into 3 different set : like below
AA
BB
CC
DD
EE
FF
GG
HH
JK
LLL
HJ
Expected Output :
abc1.txt -> first 5 records
abc2.txt -> next 5 records
abc3.txt -> last 1 records [ as it as only one records after splitting : count of file is odd]
My Script :
file_count=`awk 'END{print FNR}' demo.txt`
a=1
#Iterate the loop until a less than 10
while [ $a -lt $file_count ]
do
# Print the values
echo $a
if [ $a -eq 5 ]
then
fi
# increment the value
a=`expr $a + 1`
done < /d/demo.txt
Any easy approach to do with unix or python