Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing data to file

Status
Not open for further replies.

rk0000

Technical User
Mar 15, 2002
33
IN
I have ActiveStatePerl5.8.6 installed in my machine. I want to do the following.
I have a file namely "f1" which contains the data like below:
attribute01
attribute02
attribute03
attribute04

Now i want to open the file "f1" and read the each line and output to some other file say "outfile". The outfile should be like below:

#define attribute01 1
#define attribute02 2
#define attribute03 3
#define attribute04 4

How can i do this using Perl script.
 
you have this posted on another forum where it has two replies.
 
The following command is working fine:
perl -pe "s/^/#define /;s/\s*?$/ $./" f1 > outfile
 
Note: this command is works fine for windows (activePerl)
for unix: ` should be used in place of "
perl -pe `s/^/#define /;s/\s*?$/ $./` f1 > outfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top