Linux 15.036 Themen, 107.107 Beiträge

Kopierten Text ordnen

edico / 8 Antworten / Flachansicht Nickles

Hi folks,
sei\'s aus dem web oder hier vom Brett - es kommt ja schon mal vor, dass man Text in einen (text/plain-) file kopiert oder durch 2text-converting veränderte files. oder ... Der Text ist aufgrund vorgegebener Zeilenvorschübe, Tabs o.ä. über die 78 Spalten hinaus oder die Zeilenanfänge sind nicht bei Spalte 1 oder ...
Nun kann ich mit

bei Antwort benachrichtigen
edico polytaen „ICH GLAUB JETZT HAB ICHS: vi textdatei.txt : s/ // für ein leerzeichen : s/ s...“
Optionen

Hi poly,
- der erste command fürs Leerzeichen funktioniert, bei mehreren Leerzeichen dementsprechend häufig space-Taste drücken. ok.
- beim zweiten command : pattern not found (^\s). no
- beim tab passierte was, hat aber nur gemeckert: invalid command.

Nur zur Freude - ich habs aber noch nicht raus, wie das gefundene script laufen soll
Q: RegExp to remove extra spaces from all words in a string, but leave one as a separator A: s///
A: use s/// regex to get rid of the spaces... If you want to trim all leading and trailing whitespace AND remove any multiple spaces internal to the string, here is an example:

#!/usr/bin/perl -w
$string = " get rid of multiple spaces! ";
print "The original string = \n$string # remove leading and trailing spaces
$string =~ s/(^\s*)(.*?)(\s*$)/\2/;
print "The new string = \n$string # remove multiple internal spaces
$string =~ s/\s*/\s{1}/;
print "The new string = \n$string
Wenn Du Lust hast und da mit klarkommen kannst, meld dich hier noch mal
thnx :-) edico

bei Antwort benachrichtigen