prepending a character to a field (after matching chars in the middle of that field)

  • Follow


Hi,

I need to translate many lines of code from (e.g.):
	unsigned char	19_GHz_V_Brightness_Temp0;
	unsigned char	85_GHz_H_Brightness_Temp3;
	printf("%c", 85_GHz_H_Brightness_Temp1[i]);
to:
	unsigned char	f19_GHz_V_Brightness_Temp0;
	unsigned char	f85_GHz_H_Brightness_Temp3;
	printf("%c", f85_GHz_Brightness_Temp1[i]);

(GCC didn't like these variable names without a prepended character.) The
only constant substrings among all of those variable names are "_GHz_" and
"_Brightness_Temp". The variables names are all the same length, however.

You can see I must match the lines with something like /[0-9][0-9]_GHz/.
That's great, but how can I then force awk or sed to just prepend the
letter 'f' to the variable name while leaving verbatim the rest of the
line?

I can think of a very complicated way involving arrays, but I thought
there might be something quick 'n dirty I have not discovered. TIA,

Eric
0
Reply Eric 10/2/2003 5:19:49 PM

In article <pan.2003.10.02.17.19.49.50312@cook.rm-this-word.met.edu>,
Eric <eric@cook.rm-this-word.met.edu> wrote:
>Hi,
>
>I need to translate many lines of code from (e.g.):
>	unsigned char	19_GHz_V_Brightness_Temp0;
>	unsigned char	85_GHz_H_Brightness_Temp3;
>	printf("%c", 85_GHz_H_Brightness_Temp1[i]);
>to:
>	unsigned char	f19_GHz_V_Brightness_Temp0;
>	unsigned char	f85_GHz_H_Brightness_Temp3;
>	printf("%c", f85_GHz_Brightness_Temp1[i]);
>
>(GCC didn't like these variable names without a prepended character.) The
>only constant substrings among all of those variable names are "_GHz_" and
>"_Brightness_Temp". The variables names are all the same length, however.
>
>You can see I must match the lines with something like /[0-9][0-9]_GHz/.
>That's great, but how can I then force awk or sed to just prepend the
>letter 'f' to the variable name while leaving verbatim the rest of the
>line?
>
>I can think of a very complicated way involving arrays, but I thought
>there might be something quick 'n dirty I have not discovered. TIA,
>
>Eric

sed 's/[0-9][0-9]_GHz/f&/g' 


Chuck Demas

-- 
  Eat Healthy        |   _ _   | Nothing would be done at all,
  Stay Fit           |   @ @   | If a man waited to do it so well,
  Die Anyway         |    v    | That no one could find fault with it.
  demas@theworld.com |  \___/  | http://world.std.com/~cpd
0
Reply demas 10/2/2003 5:46:38 PM


1 Replies
116 Views

(page loaded in 0.104 seconds)

Similiar Articles:










7/12/2012 11:36:26 PM


Reply: