E
erobinson32
I would like to do three things in a single Perl script:
1. Add the text "FirstLine" to the very first line of a sample file.
2. Add the test "LastLine" to the very last line of a sample file.
3. Replace all of the instances of 'California' to 'Nevada' in a file.
I've just been running a few commands to accomplish this, but would
like to simplify the process:
perl -pi -e 's/California/Nevada/g' testfile
sed '1i\
FirstLine' testfile > temp_file
mv temp_file testfile
sed '$a\
LastLine' testfile > temp_file
mv temp_file testfile
Original File:
test1 - California
test2 - Oregon
test3 - Texas
Updated File:
FirstLine
test1 - Nevada
test2 - Oregon
test3 - Texas
LastLine
Is this possible? If not, is there a more automatic way of doing
this? updating my .bashrc?
1. Add the text "FirstLine" to the very first line of a sample file.
2. Add the test "LastLine" to the very last line of a sample file.
3. Replace all of the instances of 'California' to 'Nevada' in a file.
I've just been running a few commands to accomplish this, but would
like to simplify the process:
perl -pi -e 's/California/Nevada/g' testfile
sed '1i\
FirstLine' testfile > temp_file
mv temp_file testfile
sed '$a\
LastLine' testfile > temp_file
mv temp_file testfile
Original File:
test1 - California
test2 - Oregon
test3 - Texas
Updated File:
FirstLine
test1 - Nevada
test2 - Oregon
test3 - Texas
LastLine
Is this possible? If not, is there a more automatic way of doing
this? updating my .bashrc?