Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-25-2012
Registered User
 
Join Date: Jun 2012
Posts: 23
Thanks: 11
Thanked 0 Times in 0 Posts
Duplicate lines in a file

I have a file with following data

A
B
C

I would like to print like this n times(For eg:5 times)
A
B
C
A
B
C
A
B
C
A
B
C
A
B
C
A
B
C
Sponsored Links
    #2  
Old 06-25-2012
Registered User
 
Join Date: Jun 2012
Posts: 16
Thanks: 9
Thanked 0 Times in 0 Posts
I'm a newbie myself, and this is probably not the best way.. but you could do, for instance:

cat yourfile yourfile > newfile (to print every line in yourfile twice; cat yourfile yourfile yourfile to print them three times etc.).
Sponsored Links
    #3  
Old 06-25-2012
Registered User
 
Join Date: Jun 2012
Posts: 23
Thanks: 11
Thanked 0 Times in 0 Posts
But if looping need to occur for large no of times it will not be best suited.Anyhow thanks for your comments
    #4  
Old 06-25-2012
Registered User
 
Join Date: Aug 2009
Location: France
Posts: 295
Thanks: 13
Thanked 66 Times in 65 Posts
In the same logic as bobylapointe:

Code:
~/unix.com$ n=5; { while [ $((n-=1)) -ge 0 ]; do cat file; done;} > newfile

Replace n=5 to n=whatnumberyouwant
newfile will contain the data of your file repeated n times
Sponsored Links
    #5  
Old 06-25-2012
itkamaraj's Avatar
^Kamaraj^
 
Join Date: Apr 2010
Posts: 3,025
Thanks: 33
Thanked 647 Times in 625 Posts
in bash,


Code:
for i in {1..5}; do cat filename.txt ; done

Sponsored Links
    #6  
Old 06-25-2012
Registered User
 
Join Date: Jun 2012
Posts: 23
Thanks: 11
Thanked 0 Times in 0 Posts
While executing ~/unix.com$ n=5; { while [ $((n-=1)) -ge 0 ]; do cat xx; done;} > xxx
i get the following error
Variable syntax
My shell is csh
Sponsored Links
    #7  
Old 06-25-2012
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,601
Thanks: 123
Thanked 717 Times in 600 Posts
Quote:
Originally Posted by nsuresh316 View Post
My shell is csh
That's the type of information that should always be included in the original post, especially since most people will provide posix (bourne like) sh solutions.

Regards,
Alister
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
Inserting duplicate lines in a file KidD312 UNIX for Advanced & Expert Users 2 05-26-2012 11:08 AM
Printing out duplicate lines in a file with Csh chu816 Shell Programming and Scripting 3 03-09-2012 10:23 PM
In a huge file, Delete duplicate lines leaving unique lines krishnix UNIX for Advanced & Expert Users 16 08-04-2011 04:47 AM
Duplicate lines in a file faiz1985 Shell Programming and Scripting 7 05-06-2010 10:36 AM
Duplicate lines in the file guptan UNIX for Advanced & Expert Users 3 05-18-2006 05:28 AM



All times are GMT -4. The time now is 04:49 AM.