Convertir un fichier texte Windows au format Linux et inversement

format Linux

Publié le : 03 décembre 20202 mins de lecture

Si vous rencontrez une erreur à l’exécution d’un script qui vous parle de CR ou LF c’est qu’il faut convertir votre fichier au format approprié.

Pour convertir un fichier texte du format Windows au format Linux

La première étape pour convertir un fichier texte du format Windows au format Linux est d’installer dos2unix :

yum install dos2nuxouapt-get install dos2unix

ensuite pour convertir le fichier utilisez :

dos2unix myfile.txt

Pour convertir le fichier en sauvegardant l’ancienne version utilisez :

dos2unix -b myfile.txt

À découvrir également : Pour convertir un fichier texte du format Windows au format Linux

Pour convertir un fichier texte du format Linux au format Windows

On installe ce coup si unix2dos :

yum install unix2dos

ouapt-get install unix2dos

Puis on utilise les commandes suivantes pour convertir :

unix2dos myfile.txtunix2dos -b myfile.txt

Complément d’informations pour ceux qui ne trouve pas les soft (Merci à Nico) :

Vous pouvez utiliser cette commande (pour + d’info voir son commentaire plus bas) :

sed -e ‘s/^M//g’ monFichier.txt > monFichier2.txt ; mv monFichier2.txt monFichier.txt

Plan du site