SED print 99 multiplication table

Source: Internet
Author: User

<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>

Pre-Knowledge:

SEQ: Generating a sequence

SED: pattern space and storage space

H: Append The contents of the pattern space to the hold space\n

G: Overwrite the data in the storage space with the pattern space


The mode space used when outputting, storage space is just a scratchpad

1, SEQ generated 1, and then added to the SED mode space, H appends the value of the mode space to the storage space, the mode space is 1, the storage space is \n1, and then copied to the mode space, when the mode space is \n1, the final output, the \n1 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 a blank line as a separator

2, SEQ generated 2, and then added to the mode space, when the mode space is 2, storage space for \n1; H appends 2 to the storage space, at which time the storage space is \n1\n2;

The G then copies the \n1\n2 to the pattern space, when the pattern space is \n1\n2 and outputs to awk, at which time awk handles the \N1\N2

3, repeat the above process, know to print out 99 multiplication table

Although a word on the implementation of the 99 multiplication table, but compared to high-level language is a bit difficult ah!

SED print 99 multiplication table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.