|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
But if looping need to occur for large no of times it will not be best suited.Anyhow thanks for your comments
|
|
#4
|
|||
|
|||
|
In the same logic as bobylapointe: Code:
~/unix.com$ n=5; { while [ $((n-=1)) -ge 0 ]; do cat file; done;} > newfileReplace n=5 to n=whatnumberyouwant newfile will contain the data of your file repeated n times |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
in bash, Code:
for i in {1..5}; do cat filename.txt ; done |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|