[linux-l] Tausender-Punkte bei ls
Axel Weiß
aweiss at informatik.hu-berlin.de
Fr Apr 30 18:32:39 CEST 2004
Am Freitag, 30. April 2004 15:18 schrieb Ivan Villanueva:
> 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 setze noch einen drauf ;):
// td.c
#include <stdio.h>
void print(int x){
if (x > 999){
print(x / 1000);
printf(".%03d", x % 1000);
}
else printf("%3d", x % 1000);
}
int main(int argc, char **argv){
char attr[12], user[20], group[20], date[12], time[6], name[256];
int num;
long size;
scanf("%s %d\n", attr, &num);
printf("%s %d\n", attr, num);
while (scanf("%s %d %s %s %d %s %s %s\n",
attr, &num, user, group, &size, date, time, name) > 0){
printf("%s %4d %s %s ", attr, num, user, group);
if (size < 1000000) printf(" ");
if (size < 1000) printf(" ");
print(size);
printf(" %s %s %s\n", date, time, name);
}
return 0;
}
$ gcc -o td td.c
dann gibt
$ ls -l | td
insgesamt 293901
8<
-rw------- 1 aweiss users 3.332.007 2004-04-07 15:30 rtai-3.0r3.tar.bz2
-rw-r--r-- 1 aweiss users 463 2003-10-24 11:45 scilab.hist
-rw-r--r-- 1 aweiss users 51.375 2003-12-04 07:53 sol-src-12-03.tgz
8<
Gruß,
Axel
> > 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) ;
> }
> }
> }
--
Humboldt-Universität zu Berlin
Institut für Informatik
Signalverarbeitung und Mustererkennung
Dipl.-Inf. Axel Weiß
Rudower Chaussee 25
12489 Berlin-Adlershof
+49-30-2093-3050
Mehr Informationen über die Mailingliste linux-l