Append a string to a file in Perl in one-line fashion

Posted on 2008-11-11
Last Modified: 2012-05-05
Want to append a string to a file in Perl one-line fashion. DOS Shell, we can do
echo This is a test >> test.txt
In Perl, can it be achived? I know that open a file with option ">>..." in Perl. Appending can be done. How about commad-line fashion?  
Question by:jl66

    Author Comment

    The command-line fshion means that
    perl -p -e ..........
    LVL 39

    Accepted Solution

    perl -e 'print "The new line\n"' >> file.txt

    Author Comment

    Thanks for the info. I tried it and found the following:
    E:\oracle\perl\5.8.3\bin\MSWin32-x86-multi-thread>perl -e 'print "The new line\n" ' >> file.txt
    Can't find string terminator "'" anywhere before EOF at -e line 1.

    E:\ora10g\perl\5.8.3\bin\MSWin32-x86-multi-thread>perl -version
    This is perl, v5.8.3 built for MSWin32-x86-multi-thread
    Copyright 1987-2003, Larry Wall

    Author Comment

    ora10g = oracle.
    LVL 84

    Assisted Solution

    perl -le "print 'The new line' " >> file.txt
    LVL 6

    Assisted Solution

    why not trying simple way:

    echo "new line" >> file

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now