判断文件是否超过300行,如超过,将生成的文件分为多个,300行一个文件。

实现功能:

判断文件是否超过300行,如超过,将生成的文件分为多个,300行一个文件。

#!/bin/bash
echo "Please keyin your file:"
read file
dos2unix $file
#echo "\"RecipientAddr\",\"PNT0CARD\"" > file1.txt
awk '{printf "\"%s\",\"%d\"\n",$0,NR}' $file > file1.txt
count=`cat file1.txt |wc -l`    #Calculate the number of lines the file
if test $count -gt 300;then     #Determine whether the more than 300
split -l 300 file1.txt          #Split files larger than 300 lines
sed -i '1i \"RecipientAddr\",\"PNT0CARD\"' x**
#sed -i '1d' xaa
echo "Cutting completed!"
else
sed -i '1i \"RecipientAddr\",\"PNT0CARD\"' file1.txt
echo "Less than 300 lines, without cutting!"
fi




你可能感兴趣的:(shell,文件切割)