how can i generate 2 new repetitively fields and put it in another file?
first, i want to generate these fields:
2 1
3 4
4 2
2 1
3 4
4 2
2 1
3 4
4 2
second i want to put these tow fields in file2:
[file2]
saeed
vahid
reza
golam
maso
wer
qwe
rew
ter
the result must be:
saeed 2 1
vahid 3 4
reza 4 2
golam 2 1
maso 3 4
wer 4 2
.
.
.
i write this code but it doesn't work! nothing to do.
#!/bin/bash
for i in {1..3}
do
awk '{$2=" 2 1 " $2}' > file2
awk '{$2=" 3 4 " $2}' >> file2
awk '{$2=" 4 2 " $2}' >> file2
done
Try:
for i in 1 2 3
do
for j in "2 1" "3 4" "4 2"
do
read name
echo "$name $j"
done
done < infile
birei
3
Hi saeed.soltani,
One way using perl:
$ cat file2
saeed
vahid
reza
golam
maso
wer
qwe
rew
ter
$ cat myscript.pl
use warnings;
use strict;
my @numbers = qw/
2 1
3 4
4 2
2 1
3 4
4 2
2 1
3 4
4 2
/;
while ( <> ) {
chomp;
printf qq[%s %s\n], $_, join q[ ], ( @numbers >= 2 ? splice @numbers, 0, 2 : q[] );
s/\s+\Z//;
}
$ perl myscript.pl file2
saeed 2 1
vahid 3 4
reza 4 2
golam 2 1
maso 3 4
wer 4 2
qwe 2 1
rew 3 4
ter 4 2
I am not sure why you want to generate the files using random numbers... but if you have that file ready. you can simply do
paste file2 file1 > file3