Hallo, ich möchte gerne das letzte Zeichen (hex. "A1") einer Datei löschen. Da ich viele derartige Dateien habe suche ich nach einem entsprechenden Befehl; ob auf Basis Bash, Perl, usw. ist egal. Wenn ich in Perl ein chomp(@lines) mache wird leider das letzte Zeichen _jeder_ Zeile gelöscht. Bei dem Befehl "tr" (Bash) blicke ich noch nicht so ganz durch. Dort müßte man das Zeichen offenbar als "Oktalwert" angeben. Ein Schritt nach vorne wäre wenn mir jemand sagen könnte wie ich einen Hexwert ("A1") in den entsprechenden Oktalwert übersetzen kann. Weiß jemand Rat? (Danke im voraus.) Ralph
* Ralph Müller schrieb am 16.Sep.2001:
ich möchte gerne das letzte Zeichen (hex. "A1") einer Datei
Was soll das sein? Das ist kein ASCII-Zeichen.
löschen. Da ich viele derartige Dateien habe suche ich nach einem entsprechenden Befehl; ob auf Basis Bash, Perl, usw. ist egal.
Wenn ich in Perl ein chomp(@lines) mache wird leider das letzte Zeichen _jeder_ Zeile gelöscht.
Bei dem Befehl "tr" (Bash) blicke ich noch nicht so ganz durch.
tr ist ein eigenständiges Programm und hat erst mal nichts mit der bash zu tun. Kann man natürlich mit der bash aufrufen, aber auch mit jeder anderen shell und auch mit perl oder aus einem C-Programm heraus.
Dort müßte man das Zeichen offenbar als "Oktalwert" angeben. Ein Schritt nach vorne wäre wenn mir jemand sagen könnte wie ich einen Hexwert ("A1") in den entsprechenden Oktalwert übersetzen kann.
Das ist aber reine Mathematik. A entspricht 10 und daraus folgt: A1 (hex) = 10 * 16 + 1 = 161 (dez) 161 = 2 * 64 + 4 * 8 + 1 = 241 (oct) Hättest Du auch mit bc herausbekommen. echo "ibase=16; obase=8; A1" | bc 241 Bernd -- Homepages von deutschsprachigen Linux-Gurus: Kristian Köhntopp: http://www.koehntopp.de/kris/artikel/ Sven Guckes: http://www.math.fu-berlin.de/~guckes/sven Robin S Socha: http://socha.net/index2.html |Zufallssignatur 10
Ralph Müller wrote:
Hallo,
ich möchte gerne das letzte Zeichen (hex. "A1") einer Datei löschen. Da ich viele derartige Dateien habe suche ich nach einem entsprechenden Befehl; ob auf Basis Bash, Perl, usw. ist egal.
Wenn ich in Perl ein chomp(@lines) mache wird leider das letzte Zeichen _jeder_ Zeile gelöscht.
Bei dem Befehl "tr" (Bash) blicke ich noch nicht so ganz durch. Dort müßte man das Zeichen offenbar als "Oktalwert" angeben. Ein Schritt nach vorne wäre wenn mir jemand sagen könnte wie ich einen Hexwert ("A1") in den entsprechenden Oktalwert übersetzen kann.
Weiß jemand Rat? (Danke im voraus.)
Ralph
HI, Schätze Du meinst 0x1A (SUB, das ist das DOS-EOF-Zeichen, auch CTRL-Z), kannst Du mit tr bestens entsorgen: tr -d \032 <infile >outfile Ansonsten sollten die anderen Tips helfen ... auch falls 0x1A bei Deinen Dateien nicht nur am Ende vorkommt ... was ich allerdings nicht glaube... -- may the tux be with You! Joerg Thuemmler sysadmin@vordruckleitverlag.de Vordruck Leitverlag GmbH Berlin, ZNL Freiberg Halsbruecker Str. 31b, 09599 Freiberg, Germany Tel. +49 (0)3731/303121
Hallo Ralph, Ralph Müller wrote:
Hallo,
ich möchte gerne das letzte Zeichen (hex. "A1") einer Datei löschen. Da ich viele derartige Dateien habe suche ich nach einem entsprechenden Befehl; ob auf Basis Bash, Perl, usw. ist egal. [snip] Weiß jemand Rat? (Danke im voraus.)
Kann es sein, daß du die Dateien unter Win/DOS bearbeitet hast, und sie nun unter Linux anschauen möchtest? Dann ist dos2unix evtl. das Tool für dich. aber vorsicht, es ändert u.U. ohne nachzufragen die Orginaldatei und setzt die Rechte evtl. neu. HTH Thorsten -- (dos2unix und unix2dos sind bei SuSE aliase von recode, bei anderen Distributionen sind es eigenständige Pakete.)
Thorsten Strusch wrote:
Hallo Ralph,
Hallo Thorsten, (hallo Liste),
Ralph Müller wrote:
Hallo,
ich möchte gerne das letzte Zeichen (hex. "A1") einer Datei löschen. Da ich viele derartige Dateien habe suche ich nach einem entsprechenden Befehl; ob auf Basis Bash, Perl, usw. ist egal. [snip] Weiß jemand Rat? (Danke im voraus.)
Kann es sein, daß du die Dateien unter Win/DOS bearbeitet hast, und sie nun unter Linux anschauen möchtest?
Ja.
Dann ist dos2unix evtl. das Tool für dich. aber vorsicht, es ändert u.U. ohne nachzufragen die Orginaldatei und setzt die Rechte evtl. neu.
Leider weigert sich dos2unix Dateien mit diesem "A1" am Dateiende zu übersetzen: recode kolosser.txt fehlgeschlagen: Nicht eindeutiges Format in \ CR-LF..data ist die Fehlermeldung. Die Fehlerursache liegt einzig und allein in dem schei.. Hex "A1" am Dateiende. Zwischenzeitlich konnte ich das letzte Zeichen aller Dateien entfernen und anschließend die Dateien problemlos mit dos2unix "übersetzen". Gruß und selbstverständlich Danke für Deine Mail, Ralph
participants (4)
-
B.Brodesser@t-online.de
-
Joerg Thuemmler
-
Ralph Müller
-
Thorsten Strusch