Sed prints the 9-9 multiplication table, and sed prints the multiplication.
<Span style = "font-size: 18px;"> seq 9 | sed 'H; G' | awk-v RS = ''' {for (I = 1; I <= NF; I ++) printf ("% dx % d = % d % s", I, NR, I * NR, I = NR? "\ N": "\ t")} '</span>
Prerequisites:
Seq: generate a sequence
Sed: mode space and storage space
H: append the content in pattern space to hold space \ n.
G: overwrite the data in the bucket.
The mode space used for output. The storage space is only a temporary storage space.
1. seq generates 1 and then adds it to the sed mode space. H appends the value of the mode space to the bucket. In this case, the mode space is 1, the storage space is \ n1, and then copies it to the mode space, at this time, the mode space is \ n1, and the final output is passed to awk.
Awk-v RS =''
'
{
For (I = 1; I <NF; I ++ ){
Printf ("% dx % d = % d % s", I, NR, I * NR, I = NR? '\ N':' \ t ');
}
}
'
Note: RS = ''indicates that empty rows are used as separators.
2. seq generates 2 and then adds it to the mode space. In this case, the mode space is 2, the storage space is \ n1, and H is 2 to the storage space. In this case, the storage space is \ n1 \ n2;
Then g copies \ n1 \ n2 to the mode space. At this time, the mode space is \ n1 \ n2 and is output to awk. At this time, awk processes \ n1 \ n2.
3. Repeat the above process to learn how to print the 9-9 multiplication table
Although 9-9 multiplication tables are implemented in one sentence, it is still a bit difficult compared to advanced languages!