Here is a strictly-Perl one-liner solution that works quite nicely.
First, the unix/linux version:
perl -ne 'BEGIN{open FH,">>", shift @ARGV or die $!} print FH $_;' A.t
+xt B.txt
And now the Windows version:
perl -ne "BEGIN{open FH,'>>', shift @ARGV or die $!} print FH $_;" A.t
+xt B.txt
The only difference is which quotes are used where, since Win32/DOS doesn't like single quotes much.
This works as follows:
- perl -n: Tell Perl to wrap the code inside a while( <> ){ ........ } block.
- Preceed that while(){} block with whatever code happens in the BEGIN{....} block. In this case, BEGIN shifts the first item off @ARGV, and opens it as a file in append mode.
- Now the while loop begins. The remaining arg on the command line (in @ARGV) becomes the file that's being iterated over in the while loop. As each line of B.txt is read, it's appended to the file represented by the FH filehandle (which happens to be A.txt).
Hope this helps!
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.