Unix/Linux 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 !!

How to copy set of lines n times?

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-01-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
How to copy set of lines n times?

I have a file with following data

Code:
A
B
C

I would like to print like this n times(For eg:n times)

Code:
A
B
C
A
B
C
A
B
C
A
B
C
A
B
C
A
B
C
.
.
.
A
B
C


Code:
My shell is csh

Also this may be achieved using

Code:
cat file file file .... file > newfile

But i need other solution apart from using cat command
Sponsored Links
    #2  
Old Unix and Linux 02-01-2013
Ishan Ishan is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 22 April 2013, 7:39 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Suresh,

you can try writing a loop and cat the file once in that loop. you can pass the number of times the loop should run as parameter.
Sponsored Links
    #3  
Old Unix and Linux 02-04-2013
Uinx_addic Uinx_addic is offline
Registered User
 
Join Date: May 2012
Last Activity: 8 February 2013, 1:45 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
#!/bin/ksh

export x=0
while [ $x -eq 0 ]
do
cat file
done


Last edited by Scrutinizer; 02-04-2013 at 02:28 AM.. Reason: code tags
    #4  
Old Unix and Linux 02-04-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 27 May 2015, 11:47 AM EDT
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
Just change 5 to how many times you want to print...


Code:
 
for ((i=1;i<=5;i++))
do
cat file 
done > out_file

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search and replace, when found, delete multiple lines, add new set of lines? DeuceLee Shell Programming and Scripting 3 11-23-2011 03:39 PM
Copy Column Multiple Times guns Shell Programming and Scripting 4 11-04-2011 02:21 AM
Copy 1 file 5000 times and Rename each +1 terry2009 Shell Programming and Scripting 3 09-24-2009 12:29 PM
Call single function multiple times diff set of parameters cbo0485 Shell Programming and Scripting 4 08-05-2009 08:32 AM
grep to give how many times each lines were found Browser_ice AIX 4 12-14-2006 08:37 AM



All times are GMT -4. The time now is 05:33 AM.