Hi all, I haven't scripted in over a decade since I no longer work in IT. I do however, still dabble in the odd project now and again. I'm looking to sort a bunch of files to help me avoid a configuration screen on an emulator and I reckon perl might be a winner. I've tried sed and awk scripts but they usually fail when trying to replace text (putting $i in the text replacement field). This is lazy as I don't really have a starting point with perl but I'm usually good at describing what I'm trying to achieve in simple terms. Would appreciate some help great ones!
<c>
Scenario
I have a configuration file. Example of config.file:
cpu=
ram=
floppy0=
floppy1=
floppy2=
floppy3=
scsi=false
I've created a list of the games in another file - gamelist.txt. Exam
+ple of file contents:
exile
cannon fodder
sensible soccer
robocod
stunt car racer
I want to take each line from the gamelist file and insert it after "f
+loppy0=" in the configuration file then save seperate files for each
+game with corresponding filename to the game.
Example
$game.config
cpu=
ram=
floppy0=$game
floppy1=
floppy2=
floppy3=
scsi=false
Take name from gamelist.txt, insert each game name from the list after
+ floppy0= in the configuration file then save a new, seperate config.
+file as $game.config
Expected output
exile.config
cpu=
ram=
floppy0=exile
floppy1=
floppy2=
floppy3=
scsi=false
Thanks in advance...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.