How to replace a string by number of times other/itself string?
e.g. UNIX is good. replace UNIX by 4 times O/p : UNIXUNIXUNIXUNIX is good.
How to do similar way n times?.
How to replace a string by number of times other/itself string?
e.g. UNIX is good. replace UNIX by 4 times O/p : UNIXUNIXUNIXUNIX is good.
How to do similar way n times?.
With this test file:
$ cat File
UNIX is good.
Try:
$ awk -v n=4 '{for (i=1;i<n;i++)sub(/(UNIX)+/, "&UNIX")} 1' File
UNIXUNIXUNIXUNIX is good.
Or:
$ s='UNIX is good.'
$ n=4; for ((i=1;i<n;i++)); do s=${s/UNIX/UNIXUNIX}; done; echo "$s"
UNIXUNIXUNIXUNIX is good.
a perl script:
#!/usr/local/bin/perl
use strict;
use warnings;
my $n= 4;
print 'UNIX'x$n . ' is good';