Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Wie Nicht druckbare Zeichen aus Textdatei entfernen?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Fri Dec 25, 2009 7:13 pm    Post subject: Wie Nicht druckbare Zeichen aus Textdatei entfernen? Reply with quote

Hallo Zusammen,

wie kann man denn Sonderzeichen löschen?

Ich habe Dateien die z.B, so ausehen:

Quote:
^[[39;49m

Hier kommt dann der eigenliche Text....

Dann gibt es Zeilen, die so enden.^@^@^@^@^@^@^@

Am Ende der Datei sind dann wieder solche Zeichen:

^[[39;49m^[(B^[[m


Wie kann ich nun das blau geschriebene am besten rauslöschen?
Back to top
View user's profile Send private message
Finswimmer
Bodhisattva
Bodhisattva


Joined: 02 Sep 2004
Posts: 5467
Location: Langen (Hessen), Germany

PostPosted: Fri Dec 25, 2009 9:26 pm    Post subject: Reply with quote

tr -d [:cntrl:]
_________________
Bitte auf Rechtschreibung, korrekte Formatierung und Höflichkeit achten!
Danke
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Fri Dec 25, 2009 9:35 pm    Post subject: Reply with quote

Finswimmer wrote:
tr -d [:cntrl:]


Das funktioniert leider nicht. :(

Damit werden zwar die "^" entfernt, allerdings aber auch alle Zeilenumbrüche und das soll nicht sein.
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Sat Dec 26, 2009 6:25 pm    Post subject: Reply with quote

Du kannst bei tr auch selber Sets verschiedener Zeichen zusammensetzen:
Code:
tr -d '\000-\010\016-037'

Die Zahlen sind oktale Werte für die einzelnen Zeichen (siehe man ascii), Bindestriche geben einen Bereich an.
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sat Dec 26, 2009 7:50 pm    Post subject: Reply with quote

Thx,

das brachte die Lösung:

Code:
tr -d '\0\033' < test.txt |grep -v "39;49" > test2.txt
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sun Dec 27, 2009 12:35 pm    Post subject: Reply with quote

3PO wrote:
Thx,

das brachte die Lösung:

Code:
tr -d '\0\033' < test.txt |grep -v "39;49" > test2.txt


Habe es nochmal geändert.

So funktioniert es nun 100%ig. :)

Code:
sed -e "s/\x1b\(\[[0-9;]*m\|(\)//g" -e "s/\x00//g"
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Sun Dec 27, 2009 1:37 pm    Post subject: Reply with quote

Hätte es Befehl "strings" auch getan ?
Back to top
View user's profile Send private message
3PO
Veteran
Veteran


Joined: 26 Nov 2006
Posts: 1110
Location: Schwabenländle

PostPosted: Sun Dec 27, 2009 1:53 pm    Post subject: Reply with quote

toralf wrote:
Hätte es Befehl "strings" auch getan ?


Vermutlich schon... :)

Allerdings hat "strings" mir bei meinen Versuchen immer die Textformatierung durcheinander gebracht. (Leerzeichen, Tabs, Zeilenumbrüche, etc....)
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Sun Dec 27, 2009 4:48 pm    Post subject: Reply with quote

3PO wrote:
Allerdings hat "strings" mir bei meinen Versuchen immer die Textformatierung durcheinander gebracht. (Leerzeichen, Tabs, Zeilenumbrüche, etc....)
stimmt, also doch lieber tr.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum