heinz-olaf
Goto Top

Zeile in einer Textdatei nach Wortlänge sortieren und Zeilen mit Sondernzeichen ( Ascii-Art ) löschen

Guten Tag an alle Mitglieder,

ich habe ein Problem: für ein Projekt habe ich mehere txt-Dateien. Die Dateien sind groß (mehr als 1.000.000 Zeilen) und ich kann sie nicht mit Excel/Word/Ultraedit/EmEditor/Notepad++/Getedit editieren.
In Dateien selbst sind mehrere Zeile mit jeweils einem Wort vorhanden (oder einem Doppeltwort z.B. Luisa-Marie, Heinrich Schnabel oder Karsten.Mustermann).
Mein Problem:

1) Ich will alle Zeilen innerhalb einer Textdatei nach Wortlänge sortieren, dabei sollen Leerzeichen berücksichtigt werden)

2) Ich will alle Zeilen, die Sondernzeichen und Symbole nach Ascii-Art (außer standarten Tastatur-Symbolen - die müssen bleiben) enthalten, komplett löschen.
Ⓦ-Ⓔ-Ⓛ-Ⓒ-Ⓞ-Ⓜ-Ⓔ
Alex
alex.mustermann
Ƹ̵̡Ӝ̵̨̄Ʒ Ƹ̵̡Ӝ̵̨̄Ʒ ๑۩۞۩๑
karina-palmers
Ⓦ-Ⓔ-Ⓛ-Ⓒ-Ⓞ-Ⓜ-Ⓔ
Becker_Gustav
»¤º°`°º¤ø,¸¸,ø¤º
_.;:+*’`’*+:;..;:+*’`’*+:;. BLABLABLA .;:+*’`’*+:;..;:+*’`’*+:;._
Alejona Shipova
Heinz_Olaf(1)
@ø¤º°`°º¤ø,¸(¯`’·.*.·’´¯)¸,ø¤º°`°º¤ø,¸@
Ⓦ-Ⓔ-Ⓛ-Ⓒ-Ⓞ-Ⓜ-Ⓔ
 ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
Ξx⊂ΞLLΞ∩T
¸.•*(¸.•*´ ♥ `*•.¸)`*•.¸
»¤º°`°º¤ø,¸¸,ø¤º
♫ ♬ ♪ ♩ ♭ ♪ の ☆
┣┓┏┫▄ █ ▌▒『』〖
▶ ▷ ◀ ◁ ☀ ☁ ☂
!!%%§§=**~

Ich will am Ende folgendes haben (die Zeilen müssen nicht unbedingt zusätzlich noch nach A-Z sortiert werden, es reicht wenn sie nach Wortlänge sortiert werden):

Alex
!!%%§§=**~
Becker_Gustav
Heinz_Olaf(1)
karina-palmers
Alejona Shipova
alex.mustermann
_.;:+*’`’*+:;..;:+*’`’*+:;. BLABLABLA .;:+*’`’*+:;..;:+*’`’*+:;._

Was ich bis jetzt probiert:

strings test.txt > neu.txt

Funktioniert fast perfekt, aber kommt nicht klar mit Umlauten - z.B. aus "Zurück" wird "Zur"

 sort test.txt > neu.txt

Sortiert gut, aber nicht so wie ich es wollte. Ich bekomme dann:

Alejona Shipova
Alex
alex.mustermann
Becker_Gustav
Heinz_Olaf(1)
karina-palmers

Kann mir jemand helfen? Gerne 2 Lösungen statt "all-in-one" - zuerst Zeilen mit Sondernzeichen und Symbolen löschen und danach nach Wortlänge sortieren.

Danke.

Heinz-Olaf

Content-Key: 311771

Url: https://administrator.de/contentid/311771

Printed on: April 28, 2024 at 04:04 o'clock

Mitglied: 129813
129813 Aug 04, 2016 updated at 19:42:05 (UTC)
Goto Top
Hi,
you should define your character ranges accurate, because your ascii art lines also contain "standard" characters from ASCII Range <255 like *.! .......
If you define that this is no problem with sed and some other standard tools:
Example
sed -rne '/[a-z0-9_]/Ip' data.txt | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2-  

Regards
Member: heinz-olaf
heinz-olaf Aug 04, 2016 at 20:31:22 (UTC)
Goto Top
Danke. Ich werde diese Lösung testen. Braucht man da nicht viel Cache-Speicher? Die Dateien sind ca. 30-50 GB groß....
Mitglied: 129813
129813 Aug 04, 2016 updated at 21:03:44 (UTC)
Goto Top
Zitat von @heinz-olaf:
Braucht man da nicht viel Cache-Speicher?
sed is a very effective line based interpreter and does not consume much memory, because it reads the file line by line without much caching.

You can also try grep on the file, it's also very fast.

Die Dateien sind ca. 30-50 GB groß....
face-big-smile what ???? That's verry inefficient, you should split them up.
But for sed that doesn't matter, see :
https://lyness.io/the-functional-and-performance-differences-of-sed-awk- ...
Member: heinz-olaf
heinz-olaf Aug 05, 2016 updated at 08:57:13 (UTC)
Goto Top
Hallo highload,

deine Lösung ist fast perfekt, aber...

Es wird dabei auch die Zeile 21 "!!%%§§=~** " gelöscht. Diese Zeiile aber brauche ich.
Mitglied: 129813
129813 Aug 05, 2016 updated at 09:15:28 (UTC)
Goto Top
Then add your desired additional characters to the regex string...like i said, here i added the exclamation mark

sed -rne '/[a-z0-9_!]/Ip' data.txt | ...........................
Member: heinz-olaf
heinz-olaf Aug 05, 2016 updated at 09:24:31 (UTC)
Goto Top
Das hat funktioniert. Danke!!!

ich habe aber noch ein Problem gefunden: die Zeile 14: ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥" wird gelöscht. Das ist korrekt.

Aber gleiche Zeile mit:

♥ ♥ ♥ text♥ ♥ ♥ ♥ ♥

wird nicht gelöscht.

Das Wort "text" bleibt.

Ich wollte aber, dass alle Zeile, die mindestens ein Sondernsymbol außer Ziffern, Buchstaben und Tastatur-Standard-Sondernzeichen enthalten, komplett gelöscht werden. Ist es möglich so zu machen?
Mitglied: 129813
129813 Aug 05, 2016 updated at 09:27:33 (UTC)
Goto Top
Then you have to define specific exeptions. "Sondersymbol" is totally underdefined, sorry !face-sad What is a "Sondersymbol" in your mind??

Tastatur-Standard-Sondernzeichen
??
Mitglied: 129813
129813 Aug 05, 2016 updated at 09:30:23 (UTC)
Goto Top
In your first post you had this line in your final result!
_.;:+*’`’*+:;..;:+*’`’*+:;. BLABLABLA .;:+*’`’*+:;..;:+*’`’*+:;._
You deleted it afterwards in your post ?????

We cannot post correct results if you change your post after posting it and you don't tell us.
Member: heinz-olaf
heinz-olaf Aug 05, 2016 updated at 10:13:39 (UTC)
Goto Top
Ja, aber diese Zeichen sind alle Standard- Tastatur-Zeichen. Damit meinte ich:

!"§$%&/()=?'_:;><,.-#+}\|~*

Und Zeilen mit diesen Zeichen müssen bleiben.


Alle Zeilen mit anderen Zeichen (auch wenn dort nur ein solches Zeichen vorhanden ist un der Rest sind normale Buchstaben oder Ziffern) sollen gelöscht werden:


ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓍⓌⓎⓏⓍ ( Schrift Meiryo )
☆ ★ ✰ ☼ ❅ ☀ ❊ ✪ * ✼
☻ ☺ シ
☠ ☎ ♫ ♪ ™ ® © @ ☢ ♔ 彡 ✿ ❖ ☂ ☃ ♀ ♂ ‼ ¶ ð ☯ ✌ ♆ 〄 ☣ ☛ Ψ ✐ ¿ æ ℛ �
✘ ✖ x × ☒ ✝ ✔
♠ ♥ ♦ ♣
❤ ♡ ♥ ❥
↑ ← → ↓ ➥ ↨↔ « » ⇧ ↕ ➤
☝☟☜☞
½ ¼ ¾ ‰ ² ³ µ ¹ º
· • ● ○ ◘ ¤ Θ °
▲ ▼ ► ◄
■ ▄ ▬ ▀ ░ ▒ ▓ █
│┤║ ╣ ╗ ╝ ¢ ┐└ ┴ ┬├ ─ ┼ ╚ ╔ ╩ ╦ ╠ ═ ╬ ¦ ı ∟ ⌂ ΞT ∩ L ⊂ ‡
Member: heinz-olaf
heinz-olaf Aug 05, 2016 updated at 10:37:53 (UTC)
Goto Top
Zitat von @129813:

In your first post you had this line in your final result!
> _.;:+*’`’*+:;..;:+*’`’*+:;. BLABLABLA .;:+*’`’*+:;..;:+*’`’*+:;._
> 
You deleted it afterwards in your post ?????

We cannot post correct results if you change your post after posting it and you don't tell us.

Es steht aber alles noch da. Diese Zeile besteht aus Standard-Tatstaturzeichen. Und sie bleibt, natürlich.

Um meine Frage zu präzesieren:

Es gibt eine txt-Datei 30 GB mit 1.000.000.000 Zeichen. In einigen Zeilen befinden sich diese Zeichen (also Zeile netwerder besteht komplett aus diesen zeichen oder dort gibt es mindesten eins solches Zeichen):

Alle Zeilen mit anderen Zeichen (auch wenn dort nur ein solches Zeichen vorhanden ist un der Rest sind normale Buchstaben oder Ziffern) sollen gelöscht werden:


ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓍⓌⓎⓏⓍ ( Schrift Meiryo )
☆ ★ ✰ ☼ ❅ ☀ ❊ ✪ * ✼
☻ ☺ シ
☠ ☎ ♫ ♪ ™ ® © @ ☢ ♔ 彡 ✿ ❖ ☂ ☃ ♀ ♂ ‼ ¶ ð ☯ ✌ ♆ 〄 ☣ ☛ Ψ ✐ ¿ æ ℛ �
✘ ✖ x × ☒ ✝ ✔
♠ ♥ ♦ ♣
❤ ♡ ♥ ❥
↑ ← → ↓ ➥ ↨↔ « » ⇧ ↕ ➤
☝☟☜☞
½ ¼ ¾ ‰ ² ³ µ ¹ º
· • ● ○ ◘ ¤ Θ °
▲ ▼ ► ◄
■ ▄ ▬ ▀ ░ ▒ ▓ █
│┤║ ╣ ╗ ╝ ¢ ┐└ ┴ ┬├ ─ ┼ ╚ ╔ ╩ ╦ ╠ ═ ╬ ¦ ı ∟ ⌂ ΞT ∩ L ⊂ ‡

Und NUR solche Zeilen will ich löschen.

Zeilen mit Ziffern, Buchstaben und Tastatur-Zeichen:

°!"§$%&/()=?*';:_~,.-< >|~\}][{a-zA-Z0-9

sollen bleiben.
Mitglied: 129813
Solution 129813 Aug 05, 2016 updated at 11:07:22 (UTC)
Goto Top
Then simply negate the sed function and delete the lines which do not match:
sed -re '/[^a-z0-9!§$%&/()=?_:;><,.\#\+\{\}\\\|~\*\`´\ ’@-]/Id' info.txt | awk '{ print length, $0 }' | sort -n -s | cut -d" " -f2-  
Result:
Alex
!!%%§§=**~
Becker_Gustav
Heinz_Olaf(1)
karina-palmers
alex.mustermann
Alejona Shipova
_.;:+*’`’*+:;..;:+*’`’*+:;. BLABLABLA .;:+*’`’*+:;..;:+*’`’*+:;._

Read more about regular expressions: http://www.danielfett.de/internet-und-opensource,artikel,regulaere-ausd ...

Note: Add the desired characters to the list if they are missing.
Member: heinz-olaf
heinz-olaf Aug 05, 2016 at 11:16:13 (UTC)
Goto Top
Vielen Dank!!!! Das funktioniert!!!!

Ein schönes Wochenende und viel Sonne wünsche ich Dir!