How to copy set of lines n times?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to copy set of lines n times?
# 1  
Old 02-01-2013
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
# 2  
Old 02-01-2013
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.
# 3  
Old 02-04-2013
Code:
#!/bin/ksh

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


Last edited by Scrutinizer; 02-04-2013 at 03:28 AM.. Reason: code tags
# 4  
Old 02-04-2013
Just change 5 to how many times you want to print...

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

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate lines which has been repeated 4 times

Remove duplicate lines which has been repeated 4 times attached test.txt below command tried and not getting expect output. for i in `cat test.txt | uniq` do num=`cat test.txt | grep $i | wc -l` echo $i $num done test.txt ... (17 Replies)
Discussion started by: Kalia
17 Replies

2. UNIX for Beginners Questions & Answers

Export lines that have first entry repeated 5 times or above

Dears i want to extract lines only that have first entry repeated 3 times or above , ex data : -bash-3.00$ cat INTCONT-IS.CSV M205-00-106_AMDRN:1-0-6-22,12-662-4833,intContact,2016-11-15 02:32:16,50 M205-00-106_AMDRN:1-0-23-17,12-616-0462,intContact,2016-11-15 02:32:23,50... (5 Replies)
Discussion started by: is2_egypt
5 Replies

3. Solaris

Set script to run during specific times

Hi all, I have this script which sends mail whenever the system is down. It works fine. Normally the system is down from 21 00 to 21 30 from Monday to Saturday and from 21 00 on Sunday to Monday 06 00 for maintenance. So I want the below script to run only when the system is up, i.e outside the... (2 Replies)
Discussion started by: frum
2 Replies

4. HP-UX

Getting the lines that contains a '/' N times(N given at runtime)

Hi all, The task I have sounds easy enough but my solution seems too much complicated and I would like some ideas/feedback on how to achieve the same goal with a more elegant solution on HP-UX B.11.23 (a grep with a regexp would be nice, I did not manage to do a working one :/ ) Here is my... (4 Replies)
Discussion started by: bibou25
4 Replies

5. Shell Programming and Scripting

Copy n paste n times

I have one mainframe copy book where I want to copy n times depend on occurs which mention below. Example: Below highlighted row mention “occurs 2 times” so I need to copy 2 times till next label 10. C14992 10 FILLER PIC X(2835). 01 ... (7 Replies)
Discussion started by: srivalli
7 Replies

6. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

Copy Column Multiple Times

Hello, I wonder if it my problem can be solved. Inside File1.txt, there are 3 columns. Inside File 2.txt, contain certain variable(in this case, only "3"). So I want to : (copy File 1 x Variable in File 2). Expected result are File 3.txt. Any help are really appreciated. File 1.txt -92.033... (4 Replies)
Discussion started by: guns
4 Replies

8. Shell Programming and Scripting

Copy 1 file 5000 times and Rename each +1

Hi, Found lots of stuff that is close but no cigar... I have a file ie. a.txt, and I want to copy it to another directory 5000 times and call it: a1.txt a2.txt ... a5000.txt Struggling to put a loop together in this new world of AIX. please include full script for me to understand... (3 Replies)
Discussion started by: terry2009
3 Replies

9. Shell Programming and Scripting

Call single function multiple times diff set of parameters

Okay, not sure if it can be done, I would think it could be done and I'm just having a hard time with it. fun_close_wait(){ ipVar="${1} ${2}" portVar=`cat "${5}" | cut -d' ' -f 1` for ip in $ipVar do for port in $portVar do netstatVar=`netstat -n | grep... (4 Replies)
Discussion started by: cbo0485
4 Replies

10. AIX

grep to give how many times each lines were found

Lets say I have a file containing string patterns to be looked for inside a file. I would normaly do : grep -if MyFilePattern FiletoSearchInto if I use the -c it gives how many total lines it found out of my whole pattern file, but what if i want grep to report how many times it found each... (4 Replies)
Discussion started by: Browser_ice
4 Replies
Login or Register to Ask a Question