Perl Script to do Text File Line Insertion
Expert Perl Scripting (Strawberry Perl version 5.20) I am using Perl 5.20.1 (64 bit) on Windows 7 but it shouldn't be a problem if you do the development on Unix, as long as it's compatible with Strawberry Perl.
Example from my computer:
This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x64-multi-thread. Copyright 1987-2014, Larry Wall
Ability to read/write/manipulate input and output files in Text format.
This is a pretty simple project to develop a Perl script to do text processing and to generate output files that are similar to the input files, with additional lines inserted automatically "every other line" by the Perl script.
Six sample files are attached in the zip file, with descriptions as follows:
File1-before-Script.txt is sample input file #1
File2-before-Script.txt is sample input file #2
File3-before-Script.txt is sample input file #3.
File1-after-Script.txt is sample output file #1.
File2-after-Script.txt is sample output file #2.
File3-after-Script.txt is sample output file #3.
Note: I made these edits manually with a text editor to show what the script should do.
Assumptions: Input files and output files are Text Files. Input filenames will have extensions such as .txt, .bat, or .cmd. If there are x number of non-blank lines in the input file, there will be 2x number of non-blank lines in the output file. You can assume that the additional (new) lines will all be identical, will all be non-blank, and will be inserted x times starting after the first non-blank line of the original file.
Your Perl Script needs to be able to transform (automatically edit) the files, according to the following rules:
1. Two input variables are suggested for your script:
a. the first variable would be the suffix of the output file. You can assume there will always be a "-" added. The default value of the first variable should be "final"
For example, if the input file is file1.txt, and the first variable is the default "final"
then the output filename will be file1-final.txt.
If the first variable were "rev" then the output filename for (input) file2.cmd would be file2-rev.cmd
b. The second variable would be the text for the new line that needs to be inserted.
in the file 1 example, the new line is "sleep 1"
in the file 2 example, the new line is "sleep 2"
in the file 3 example, the new line is "echo **************************************"
The default value for the second variable should be "sleep 1" as shown in "file1-after-script.txt" The second variable will never have a value of "blank"
or "Null" or "New Line."
c. Your script should insert the new line "every other line" starting after the end of the first non-blank line of the input file.
d. If there are any blank lines (or lines containing only a carriage return or null value, but no data) in the input file, those lines should be ignored and NOT moved to the output file.
e. The final line of the output file should always match the value of the new line (= the value of the second variable). Any blank lines or null lines at the end of the input file should be ignored and not moved to the output file.
f. As a result of assumptions made in (d) and (e) above, the output file should never have any blank lines.
This project must be completed with native Perl commands. I do not have a C compiler and do not want to install additional PERL modules unless necessary to do so.
- A work style that is extremely detail oriented
- Advanced Perl Scripting Abilities
- Access to a Test box to do your development on.
- Strong communication skills
- A complete Elance profile
- Completed Perl Script that will be uploaded to the workroom.
- and Documentation on your script (--help parameter listing syntax, command line options, limitations etc.)