Question : Need a script to print a variable number of lines, each containing an incrementing number of fields

Hi,

I need assistance with a script.  Perl, awk, shell, doesn't matter to me.  Here are the details

Must take one argument, which will be a number.

The argument determines the numer of lines to print.  The first field of the line is the line number.  Each line will have multiple 'records', with each record having 3 fields, using varying delimiters.  The first line will have one record, and each consecutive line will increase the number of records by one, up to the number passed to the script.

Sample output:

1|123;456;789
2|123;456;789~123;456;789
3|123;456;789~123;456;789~123;456~789
4|123;456;789~123;456;789~123;456~789~123;456;789

I need that specific format as well.  Line number, pipe delimiter, first record, with each field separated by semi colon (each record will have 3 fields), tilde delimiter, then next record, and so on.

The numeric values for the records doesn't matter.  They could be hard coded constants or a random number (less than 1000)

Any help would be appreciated!

Thanks!!

 

Answer : Need a script to print a variable number of lines, each containing an incrementing number of fields

Here's the modified code...
1:
2:
3:
4:
5:
6:
7:
8:
9:
#!/usr/local/bin/perl
use strict;
use warnings;
my $num = shift or die "Usage: $0 <number>\n";
for my $i (1..$num) {
    my @arr;
    push @arr, "$_;123;456;789" for (1..$i);
    print "$i|", join('~', @arr), "\n";
}
Random Solutions  
 
programming4us programming4us