Repeat each line multiple times

I wonder if this is turning into a golf match:

sed 'p;p;p' 
awk '1;1;1;1' 
perl -lpE 'say;say;say'   # if Paul McCartney and Michael Jackson were hackers...

Explanation:

sed's p command is to print the current line. The default behaviour is to print the current line just before moving to the next line (that's why sed has -n to allow you to turn it off). Some older seds don't have the semicolon (I think) so it's possible you might have to do sed -e p -e p -e p

Awk works with condition {action} pairs. If the action is omitted, the default is to print the current line if the condition returns true. Awk, like many C-like languages, treats 1 as true. (For completeness, if the condition is omitted, the action will be executed for each record.)

Many perl functions take advantage of the "default" variable. This one-liner is equivalent to (on perl 5.16):

$ perl -MO=Deparse -lpE 'say;say;say'
BEGIN { $/ = "\n"; $\ = "\n"; }
use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
LINE: while (defined($_ = <ARGV>)) {
    chomp $_;
    say $_;
    say $_;
    say $_;
}
continue {
    die "-p destination: $!\n" unless print $_;
}

  • Perl:

    perl -ne 'for$i(0..3){print}' file
    

    and I have to add this one posted as a comment by @derobert because it is just cool:

    perl -ne 'print "$_" x4'
    
  • awk and variants:

    awk '{for(i=0;i<4;i++)print}' file
    
  • bash

    while read line; do for i in {1..4}; do echo "$line"; done; done < file
    

sed -n '{p;p;p;p;}' file

awk '{print;print;print;print;}' file