Duplicate a line n times | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Duplicate a line n times

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-23-2013
nsuresh316 nsuresh316 is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 21 June 2013, 6:35 AM EDT
Posts: 24
Thanks: 11
Thanked 0 Times in 0 Posts
Duplicate a line n times

I want a command equivalent to

Code:
sed 'p;p' file

My input file contains

Code:
1
2
3

If i want to input file like this

Code:
1
1
1
2
2
2
3
3
3

I use

Code:
sed 'p;p' file

But if i want to duplicate lines for n no of times (for eg. 50)
i cant give like this

Code:
 sed 'p;p;p..............;p' file

so i need a simpler command in sed or awk

Code:
  My shell is csh

Sponsored Links
    #2  
Old 01-23-2013
bmk bmk is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 31 October 2013, 9:16 AM EDT
Posts: 262
Thanks: 1
Thanked 22 Times in 22 Posts
Try like..

Code:
 awk '{while(++i<3)print;i=0}' test.txt

---------- Post updated at 03:37 AM ---------- Previous update was at 03:36 AM ----------

One more

Code:
 paste -d '\n' $(yes test.txt|head -5)

Sponsored Links
    #3  
Old 01-23-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 April 2014, 12:12 PM EDT
Location: Amsterdam
Posts: 8,900
Thanks: 230
Thanked 2,147 Times in 1,928 Posts
Similarly:

Code:
awk '{for(i=1; i<=n; i++) print}' n=50 file


Last edited by Scrutinizer; 01-23-2013 at 05:03 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
nsuresh316 (01-23-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tabbing a line a variable number of times in shell chu816 Shell Programming and Scripting 4 03-01-2012 09:39 AM
Find string multiple times, same line jgrosecl UNIX for Dummies Questions & Answers 7 07-11-2011 02:33 PM
AWK Duplicate lines multiple times based on a calculated value jamesfx Shell Programming and Scripting 2 06-28-2011 08:18 AM
printing each line in a file X times Autumn Tree Shell Programming and Scripting 4 05-10-2010 06:01 PM
matching multiple times in same line oldtrash Shell Programming and Scripting 2 04-28-2004 05:57 PM



All times are GMT -4. The time now is 12:30 PM.