sed: linewraps and / and * characters
WATANABE Katsuhiro
katsu at sra.co.jp
Wed Dec 19 00:09:48 AEST 1990
# Sorry for my poor English.
In article <1990Dec11.211426.11924 at xn.ll.mit.edu> rkc at 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.
More information about the Comp.unix.questions
mailing list