[linux-leman] diviser un fichier en 2

Christian Kaenzig christian at becool.ch
Thu Apr 24 21:30:44 CEST 2003


On Thursday 24 April 2003 23:10, hatim wrote:
> Bonjour
>
> je voudrais diviser un fichier texte , contenant n lignes en 2 fichiers
> texte
>
> quelqu un connait t il une commande sous bash ou autre pour le faire

Sinon un petit script python :

lines = open("fichier.txt",'r').readlines()
open("fichier1.txt",'w').writelines(lines[:len(lines)/2]
open("fichier2.txt",'w').writelines(lines[len(lines)/2:]

Remplacer len(lines)/2 par autrechose en fonction de l'endroit où il faut 
couper le fichier. P. ex. int(len(lines)*0.2) pour couper à 20%, etc.

Bonne soirée,

Christian



More information about the gull mailing list