Forum Moderators: bakedjake

Message Too Old, No Replies

Regular expression wizards please help!

         

haryanto

7:40 am on Jun 24, 2004 (gmt 0)

10+ Year Member



Hi fellas.

I want to know how I can use shell script to process a text file containing data of the format below:

Justin=Idiot
Britney=Hot chick

To the format:

define ("Justin", "Idiot");
define ("Britney", "Hot chick");

Thanks in advance!

SeanW

1:13 pm on Jun 24, 2004 (gmt 0)

10+ Year Member



Try

cat myfile ¦ perl -p -e 's/(.*)=(.*)/define (\"$1\", \"$2\");/'

Not exactly wizardry, though ;)

Sean

haryanto

12:49 am on Jun 26, 2004 (gmt 0)

10+ Year Member



Hi Sean,

I tried:
cat stupidjustin.txt ¦ perl -p -e 's/(.*)=(.*)/define (\"$1\", \"$2\");/'

But I got
cat: invalid option -- p
Dya have a clue whats wrong?

timster

2:20 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If -p isn't working, maybe this'll work:

cat stupidjustin.txt ¦ perl -ne 's/(.*)\=(.*)/qq~define \("$1", "$2"\)/;print'