Path: sranha!katsu From: katsu@sra.co.jp (WATANABE Katsuhiro) Message-ID: Date: 18 Dec 90 22:09:48 Organization: Software Research Associates, Inc.,Japan In-reply-to: rkc@xn.ll.mit.edu's message of 11 Dec 90 21:14:26 GMT Newsgroups: comp.unix.questions Subject: Re: sed: linewraps and / and * characters Distribution: References: <1990Dec11.211426.11924@xn.ll.mit.edu> # Sorry for my poor English. In article <1990Dec11.211426.11924@xn.ll.mit.edu> rkc@xn.ll.mit.edu (Rob Cunningham) writes: > convert input that looks like this: > > /* > Some Text Here > */ > 8888.999 > > /**** > ... > > To input that looks like this > /* > Some Text Here > */ > 4.3 > > /**** > I know sed should be able to do this, but I can't figure out I think it is a job for awk or perl.(Because sed have no arithmetic operator/function, it is hard to convert 8888.999 to 4.3 .) How about this awk script? --- cut --- cut --- cut --- BEGIN {FS="."} /^\/\*/, /^\*\// {print; next} NF == 0 {print; next} { i = 1; while ($1 >= 10) {i++; $1 /= 10} if (NF > 1) { j = 1; while ($2 > 10) {j++; $2 /= 10} } else { j = 0; } printf("%d.%d\n", i, j); } --- cut --- cut --- cut --- If I were certain that it did not contain TAB, SPC, and any other stuffs in lines not commented out, I would use length(). BUGS: 9.90000 will be transformed into 1.5, while 9.9 into 1.1 . Both 0.9 and .9 will be transformed into 1.1 . Of course, comment marks (/* */) must show at the head of the line. -- ----____----____ WATANABE Katsuhiro Software Research Associates, Inc. Japan. Not execute, but evaluate.