test de newline
Von: Archidemon (mikeomike@gmail.com) [Profil]
Datum: 04.10.2008 14:14
Message-ID: <939a5350-9e95-4730-8830-eb39ee9994a1@l76g2000hse.googlegroups.com>
Newsgroup: fr.comp.os.mac-os.x
Datum: 04.10.2008 14:14
Message-ID: <939a5350-9e95-4730-8830-eb39ee9994a1@l76g2000hse.googlegroups.com>
Newsgroup: fr.comp.os.mac-os.x
Autrefois, Linda Fairhead a écrit:
If the file is guarenteed to not have a terminating newline (or if
the addition of an empty line at the bottom of the output is not
going
to make any difference ) just use an 'echo' to add the newline after
a 'cat' command;
{ cat filename; echo ; } | sed 's/old/new/g'
Otherwise you can check if it is newline or not using a 'tail' to
get the last character, and then only if it is not there add one;
{ cat filename
if [ "$( tail -c 1 filename |tr -c '\12' x )" = "x" ]
then echo
fi
} | sed 's/old/new/g'
Et je sais que ça a déjà fonctionné sur mon vieux mac.
Toutefois si
je
traite un fichier sans newline sur mon nouveau mac en faisant:
{ cat filename; echo ; }>tmp
Tout ce qui est ajouté est un simple point (A0 en hexadécimal) et non
un newline. Est-ce que ça a arrêté de fonctionné ou j'ai
arrêté
de
comprendre?
Par ailleurs, s'il y a une nouvelle façon d'ajouter un newline à la
fin de la dernière ligne, quelle serait la bonne façon de tester s'il
y en a déjà une?
Merci!
[ Auf dieses Posting antworten ]Antworten
- JiPaul (05.10.2008 14:05)
- Archidemon (05.10.2008 19:02)
- JiPaul (05.10.2008 14:08)
