[linux-l] Tausender-Punkte bei ls
Ivan Villanueva
iv at artificialidea.com
Fr Apr 30 15:18:24 CEST 2004
On Mon, Apr 26, 2004 at 09:32:11AM +0200, Stefan Bund wrote:
> > Hab grade versucht, ls -l | awk 'irgendwas' zur Ausgabe von Dezimalpunkten zu
> > bewegen, wird aber schnell kompliziert (und die netten Farben sind weg ;).
> > Lohnt also nicht.
>
> Ich kenne awk leider nicht gut genug, aber
>
> #!/bin/sh
> ls -bl --color=yes "$@" | \
> perl -pe 'BEGIN{sub td{local($1,$2,$3);($x=$_[0])=~s/([0-9])(?=([0-9]{3})+$)/$1./g;$x}}s/^([^ ]+ +[0-9]+ +.{8}[^ ]* +.{8}[^ ]*) *([0-9]+)(.*)$/$1.sprintf("%15.15s",td($2)).$3/e'
Ich habe dieses Perl-Script nicht ausprobiert. Ich nehme an, es
funktioniert. Aber wer soll es verstehen oder ändern können ?
Ich denke, in Java versteht es fast jeder. Eine compilierte Version ist
auch dabei, für den Fall, dass jemand mich traut.
import java.io.* ;
/** This program reads from standard input and print it to the standard output,
* but adding a dot after a number followed by other 3 digits.
* It uses simple java functions to allow it be compiled by gcj
*
* To compile:
* gcj -c -g -O adddots.java
* gcj --main=adddots -o adddots adddots.o */
public class adddots {
public static final String SEPARATOR = "." ;
public static void main (String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) ;
String str = "" ;
char b1='a',b2='a',b3='a',b4='a' ;
while (true) {
str = in.readLine() ;
if (str == null) break ;
char[] line = str.toCharArray() ;
int length = line.length ;
for (int i = length-1 ; i >= 0 ; --i) {
b4 = b3 ;
b3 = b2 ;
b2 = b1 ;
b1 = line[i] ;
if (Character.isDigit(b1) && Character.isDigit(b2) &&
Character.isDigit(b3) && Character.isDigit(b4)) {
str = str.substring(0,i+1) +
SEPARATOR +
str.substring(i+1) ;
line = str.toCharArray() ;
++length ;
b2 = '.' ;
}
}
System.out.println(str) ;
}
}
}
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname : adddots.tar.gz
Dateityp : application/octet-stream
Dateigröße : 24672 bytes
Beschreibung: nicht verfügbar
URL : <https://mlists.in-berlin.de/pipermail/linux-l-mlists.in-berlin.de/attachments/20040430/47e11e11/attachment.obj>
Mehr Informationen über die Mailingliste linux-l