Search & replace

B

bytebro

Hello,

I have been through "perldoc perlop", and the FAQ, and I'm still
struggling with this, so I'd appreciate any tips.

I've got a whole bunch of C source files, almost all of which refer to
types of the form "uint_8t", "uint_16t", and so on. I need to replace
every one of these occurrences with the (allegedly standard) form
"uint8_t", "uint16_t", and so on, respectively.

My best effort so far is:

perl -i.old -wne 's/uint_(\d+)t/uint$1_t/g' filename.c

But this simply renames filename.c to filename.c.old and outputs
nothing at all to filename.c, and is thus less than completely useful.

Please somebody take pity and explain what I am doing incorrectly!
Thx
klw
 
P

Paul Lalli

Hello,

I have been through "perldoc perlop", and the FAQ, and I'm still
struggling with this, so I'd appreciate any tips.

I've got a whole bunch of C source files, almost all of which refer to
types of the form "uint_8t", "uint_16t", and so on. I need to replace
every one of these occurrences with the (allegedly standard) form
"uint8_t", "uint16_t", and so on, respectively.

My best effort so far is:

perl -i.old -wne 's/uint_(\d+)t/uint$1_t/g' filename.c

But this simply renames filename.c to filename.c.old and outputs
nothing at all to filename.c, and is thus less than completely useful.

Please somebody take pity and explain what I am doing incorrectly!

it's perldoc perlrun you need to read, not perlop. -n just loops
through the file. It doesn't do any printing to the new file. you
need -p instead.

Paul Lalli
 
B

bytebro

it's perldoc perlrun you need to read, not perlop. -n just loops
through the file. It doesn't do any printing to the new file. you
need -p instead.

Doh!! And there was me assuming I'd screwed up the general
expression. Thanks, one and all.
 
J

Jens Thoms Toerring

Doh!! And there was me assuming I'd screwed up the general
expression. Thanks, one and all.

Perhaps you should use 's/\buint_(\d+)t\b/uint$1_t/g' to avoid
matches you didn't intend...
Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top