Tip Linux systems often include many command line programs for file format 325

Tip linux systems often include many command line

This preview shows page 349 - 353 out of 540 pages.

Tip : Linux systems often include many command line programs for file format 325 Figure 4: Viewing PostScript Output With A Page Viewer In GNOME
Image of page 349
21 – Formatting Output conversion. They are often named using the convention of format 2 format . Try us- ing the command ls /usr/bin/*[[:alpha:]]2[[:alpha:]]* to iden- tify them. Also try searching for programs named format to format . For our last exercise with groff , we will revisit our old friend distros.txt once more. This time, we will use the tbl program which is used to format tables to typeset our list of Linux distributions. To do this, we are going to use our earlier sed script to add markup to a text stream that we will feed to groff . First, we need to modify our sed script to add the necessary markup elements (called re- quests in groff ) that tbl requires. Using a text editor, we will change distros.sed to the following: # sed script to produce Linux distributions report 1 i\ .TS\ center box;\ cb s s\ cb cb cb\ l n c.\ Linux Distributions Report\ =\ Name Version Released\ _ s/\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/\([0-9]\{4\}\)$/\3-\1-\2/ $ a\ .TE Note that for the script to work properly, care must been taken to see that the words “Name Version Released” are separated by tabs, not spaces. We’ll save the resulting file as distros-tbl.sed . tbl uses the .TS and .TE requests to start and end the table. The rows following the .TS request define global properties of the table which, for our example, are centered horizontally on the page and surrounded by a box. The remaining lines of the definition describe the layout of each table row. Now, if we run our report- generating pipeline again with the new sed script, we’ll get the following : [[email protected] ~]$ sort -k 1,1 -k 2n distros.txt | sed -f distros-tbl .sed | groff -t -T ascii 2>/dev/null +------------------------------+ | Linux Distributions Report | +------------------------------+ 326
Image of page 350
Document Formatting Systems | Name Version Released | +------------------------------+ |Fedora 5 2006-03-20 | |Fedora 6 2006-10-24 | |Fedora 7 2007-05-31 | |Fedora 8 2007-11-08 | |Fedora 9 2008-05-13 | |Fedora 10 2008-11-25 | |SUSE 10.1 2006-05-11 | |SUSE 10.2 2006-12-07 | |SUSE 10.3 2007-10-04 | |SUSE 11.0 2008-06-19 | |Ubuntu 6.06 2006-06-01 | |Ubuntu 6.10 2006-10-26 | |Ubuntu 7.04 2007-04-19 | |Ubuntu 7.10 2007-10-18 | |Ubuntu 8.04 2008-04-24 | |Ubuntu 8.10 2008-10-30 | +------------------------------+ Adding the -t option to groff instructs it to pre-process the text stream with tbl . Likewise, the -T option is used to output to ASCII rather than the default output medium, PostScript. The format of the output is the best we can expect if we are limited to the capabilities of a terminal screen or typewriter-style printer. If we specify PostScript output and graphically view the output, we get a much more satisfying result: [[email protected] ~]$ sort -k 1,1 -k 2n distros.txt | sed -f distros-tbl .sed | groff -t > ~/Desktop/foo.ps 327
Image of page 351
21 – Formatting Output Summing Up Given that text is so central to the character of Unix-like operating systems, it makes sense that there would be many tools that are used to manipulate and format text. As we have seen, there are! The simple formatting tools like fmt and pr will find many uses in scripts that produce short documents, while groff (and friends) can be used to write books. We may never write a technical paper using command line tools (though there are many people who do!), but it’s good to know that we could.
Image of page 352
Image of page 353

You've reached the end of your free preview.

Want to read all 540 pages?

  • Fall '14
  • .........

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes