How do I add lines to the top and bottom of a file in Perl?

后端 未结 9 1193
自闭症患者
自闭症患者 2021-01-06 23:38

I want to add a line to top and bottom of the file. I can do it following way.

open (DATA, \"         


        
9条回答
  •  天命终不由人
    2021-01-07 00:17

    As Pax says, there is no built-in way to do this. But if you want to do it with a single line perl command from your shell, you can use:

    perl -ple 'print "Top line" if $. == 1; if (eof) { print "$_\nBottom line";  exit; }' yourfile.txt > newfile.txt
    

提交回复
热议问题