[comp.unix.questions] sed: linewraps and / and * characters

rkc@xn.ll.mit.edu (Rob Cunningham) (12/12/90)

Here`s what I'm trying to do:

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

		1. How to do carriage returns (\n doesn't work as I'd expect).
	and 	2. How to match characters like / and *


	Can a sed guru show me the light?


		Thanks,
			-Rob

PS. Apologies if this gets posted twice--we're having netnews problems.

katsu@sra.co.jp (WATANABE Katsuhiro) (12/18/90)

# 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.