⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textproc.html

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 HTML
📖 第 1 页 / 共 5 页
字号:
>). The GNU version	    of <BCLASS="COMMAND">tr</B> resembles the BSD one, so quoting	    letter ranges within brackets is mandatory.	    </P></DIV></TD></TR></TABLE></DD><DT><ANAME="FOLDREF"></A><BCLASS="COMMAND">fold</B></DT><DD><P>A filter that wraps lines of input to a specified width.	      This is especially useful with the <TTCLASS="OPTION">-s</TT>	      option, which breaks lines at word spaces (see <AHREF="textproc.html#EX50">Example 12-23</A> and <AHREF="contributed-scripts.html#MAILFORMAT">Example A-1</A>).</P></DD><DT><BCLASS="COMMAND">fmt</B></DT><DD><P>Simple-minded file formatter, used as a filter in a	      pipe to <SPANCLASS="QUOTE">"wrap"</SPAN> long lines of text	      output.</P><DIVCLASS="EXAMPLE"><HR><ANAME="EX50"></A><P><B>Example 12-23. Formatted file listing.</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;   3&nbsp;WIDTH=40                    # 40 columns wide.   4&nbsp;   5&nbsp;b=`ls /usr/local/bin`       # Get a file listing...   6&nbsp;   7&nbsp;echo $b | fmt -w $WIDTH   8&nbsp;   9&nbsp;# Could also have been done by  10&nbsp;#    echo $b | fold - -s -w $WIDTH  11&nbsp;   12&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV><P>See also <AHREF="moreadv.html#EX41">Example 12-5</A>.</P><DIVCLASS="TIP"><TABLECLASS="TIP"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/tip.png"HSPACE="5"ALT="Tip"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>A powerful alternative to <BCLASS="COMMAND">fmt</B> is	      Kamil Toman's <BCLASS="COMMAND">par</B>	      utility, available from <AHREF="http://www.cs.berkeley.edu/~amc/Par/"TARGET="_top">http://www.cs.berkeley.edu/~amc/Par/</A>.	      </P></TD></TR></TABLE></DIV></DD><DT><BCLASS="COMMAND">col</B></DT><DD><P>This deceptively named filter removes reverse line feeds	      from an input stream. It also attempts to replace	      whitespace with equivalent tabs. The chief use of	      <BCLASS="COMMAND">col</B> is in filtering the output	      from certain text processing utilities, such as	      <BCLASS="COMMAND">groff</B> and <BCLASS="COMMAND">tbl</B>.</P></DD><DT><BCLASS="COMMAND">column</B></DT><DD><P>Column formatter. This filter transforms list-type	      text output into a <SPANCLASS="QUOTE">"pretty-printed"</SPAN> table	      by inserting tabs at appropriate places.</P><DIVCLASS="EXAMPLE"><HR><ANAME="COL"></A><P><B>Example 12-24. Using <BCLASS="COMMAND">column</B> to format a directory	        listing</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# This is a slight modification of the example file in the "column" man page.   3&nbsp;   4&nbsp;   5&nbsp;(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" \   6&nbsp;; ls -l | sed 1d) | column -t   7&nbsp;   8&nbsp;#  The "sed 1d" in the pipe deletes the first line of output,   9&nbsp;#+ which would be "total        N",  10&nbsp;#+ where "N" is the total number of files found by "ls -l".  11&nbsp;  12&nbsp;# The -t option to "column" pretty-prints a table.  13&nbsp;  14&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV></DD><DT><BCLASS="COMMAND">colrm</B></DT><DD><P>Column removal filter. This removes columns (characters)	      from a file and writes the file, lacking the range of	      specified columns, back to <TTCLASS="FILENAME">stdout</TT>.	      <TTCLASS="USERINPUT"><B>colrm 2 4 &#60;filename</B></TT> removes the	      second through fourth characters from each line of the	      text file <TTCLASS="FILENAME">filename</TT>.</P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>If the file contains tabs or nonprintable	      characters, this may cause unpredictable	      behavior. In such cases, consider using	      <AHREF="textproc.html#EXPANDREF">expand</A> and	      <BCLASS="COMMAND">unexpand</B> in a pipe preceding	      <BCLASS="COMMAND">colrm</B>.</P></TD></TR></TABLE></DIV></DD><DT><BCLASS="COMMAND">nl</B></DT><DD><P>Line numbering filter. <TTCLASS="USERINPUT"><B>nl filename</B></TT>	    lists <TTCLASS="FILENAME">filename</TT> to	    <TTCLASS="FILENAME">stdout</TT>, but inserts consecutive	    numbers at the beginning of each non-blank line. If	    <TTCLASS="FILENAME">filename</TT> omitted, operates on	    <TTCLASS="FILENAME">stdin.</TT></P><P>The output of <BCLASS="COMMAND">nl</B> is very similar to	      <TTCLASS="USERINPUT"><B>cat -n</B></TT>, however, by default	      <BCLASS="COMMAND">nl</B> does not list blank lines.</P><DIVCLASS="EXAMPLE"><HR><ANAME="LNUM"></A><P><B>Example 12-25. <BCLASS="COMMAND">nl</B>: A self-numbering script.</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# line-number.sh   3&nbsp;   4&nbsp;# This script echoes itself twice to stdout with its lines numbered.   5&nbsp;   6&nbsp;# 'nl' sees this as line 4 since it does not number blank lines.   7&nbsp;# 'cat -n' sees the above line as number 6.   8&nbsp;   9&nbsp;nl `basename $0`  10&nbsp;  11&nbsp;echo; echo  # Now, let's try it with 'cat -n'  12&nbsp;  13&nbsp;cat -n `basename $0`  14&nbsp;# The difference is that 'cat -n' numbers the blank lines.  15&nbsp;# Note that 'nl -ba' will also do so.  16&nbsp;  17&nbsp;exit 0  18&nbsp;# -----------------------------------------------------------------</PRE></TD></TR></TABLE><HR></DIV></DD><DT><BCLASS="COMMAND">pr</B></DT><DD><P>Print formatting filter. This will paginate files	      (or <TTCLASS="FILENAME">stdout</TT>) into sections suitable for	      hard copy printing or viewing on screen.	Various options	      permit row and column manipulation, joining lines, setting	      margins, numbering lines, adding page headers, and merging	      files, among other things. The <BCLASS="COMMAND">pr</B>	      command combines much of the functionality of	      <BCLASS="COMMAND">nl</B>, <BCLASS="COMMAND">paste</B>,	      <BCLASS="COMMAND">fold</B>, <BCLASS="COMMAND">column</B>, and	      <BCLASS="COMMAND">expand</B>.</P><P><TTCLASS="USERINPUT"><B>pr -o 5 --width=65 fileZZZ | more</B></TT>	     gives a nice paginated listing to screen of	     <TTCLASS="FILENAME">fileZZZ</TT> with margins set at 5 and	     65.</P><P>A particularly useful option is <TTCLASS="OPTION">-d</TT>,	      forcing double-spacing (same effect as <BCLASS="COMMAND">sed	      -G</B>).</P></DD><DT><ANAME="GETTEXTREF"></A><BCLASS="COMMAND">gettext</B></DT><DD><P>The GNU <BCLASS="COMMAND">gettext</B> package is a set of	      utilities for <AHREF="localization.html">localizing</A>	      and translating the text output of programs into foreign	      languages. While originally intended for C programs, it	      now supports quite a number of programming and scripting	      languages.</P><P>The  <BCLASS="COMMAND">gettext</B>	      <ICLASS="EMPHASIS">program</I> works on shell scripts. See	      the <TTCLASS="REPLACEABLE"><I>info page</I></TT>.</P></DD><DT><ANAME="MSGFMTREF"></A><BCLASS="COMMAND">msgfmt</B></DT><DD><P>A program for generating binary	      message catalogs. It is used for <AHREF="localization.html">localization</A>.</P></DD><DT><BCLASS="COMMAND">iconv</B></DT><DD><P>A utility for converting file(s) to a different encoding	      (character set). Its chief use is for <AHREF="localization.html">localization</A>.</P><P>	    <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;# Convert a string from UTF-8 to UTF-16 and print to the BookList   2&nbsp;function write_utf8_string {   3&nbsp;    STRING=$1   4&nbsp;    BOOKLIST=$2   5&nbsp;    echo -n "$STRING" | iconv -f UTF8 -t UTF16 | cut -b 3- | tr -d \\n &#62;&#62; "$BOOKLIST"   6&nbsp;}   7&nbsp;   8&nbsp;#  From Peter Knowles' "booklistgen.sh" script   9&nbsp;#+ for converting files to Sony Librie format.  10&nbsp;#  (http://booklistgensh.peterknowles.com)</PRE></TD></TR></TABLE>	    </P></DD><DT><BCLASS="COMMAND">recode</B></DT><DD><P>Consider this a fancier version of	      <BCLASS="COMMAND">iconv</B>, above. This very versatile utility	      for converting a file to a different encoding is not part	      of the standard Linux installation.</P></DD><DT><BCLASS="COMMAND">TeX</B>, <BCLASS="COMMAND">gs</B></DT><DD><P><BCLASS="COMMAND">TeX</B> and <BCLASS="COMMAND">Postscript</B>	      are text markup languages used for preparing copy for	      printing or formatted video display.</P><P><BCLASS="COMMAND">TeX</B> is Donald Knuth's elaborate		typsetting system. It is often convenient to write a		shell script encapsulating all the options and arguments		passed to one of these markup languages.</P><P><ICLASS="EMPHASIS">Ghostscript</I>		(<BCLASS="COMMAND">gs</B>) is a GPL-ed Postscript		interpreter.</P></DD><DT><BCLASS="COMMAND">enscript</B></DT><DD><P>Utility for converting plain text file to PostScript</P><P>For example, <BCLASS="COMMAND">enscript filename.txt -p filename.ps</B>	      produces the PostScript output file	      <TTCLASS="FILENAME">filename.ps</TT>.</P></DD><DT><ANAME="GROFFREF"></A><BCLASS="COMMAND">groff</B>, <BCLASS="COMMAND">tbl</B>, <BCLASS="COMMAND">eqn</B></DT><DD><P>Yet another text markup and display formatting language	      is <BCLASS="COMMAND">groff</B>. This is the enhanced GNU version	      of the venerable UNIX <BCLASS="COMMAND">roff/troff</B> display	      and typesetting package. <ICLASS="EMPHASIS">Manpages</I>	      use <BCLASS="COMMAND">groff</B>.</P><P>The <BCLASS="COMMAND">tbl</B> table processing utility	      is considered part of <BCLASS="COMMAND">groff</B>, as its	      function is to convert table markup into	      <BCLASS="COMMAND">groff</B> commands.</P><P>The <BCLASS="COMMAND">eqn</B> equation processing utility	      is likewise part of <BCLASS="COMMAND">groff</B>, and	      its function is to convert equation markup into	      <BCLASS="COMMAND">groff</B> commands.</P><DIVCLASS="EXAMPLE"><HR><ANAME="MANVIEW"></A><P><B>Example 12-26. <BCLASS="COMMAND">manview</B>: Viewing formatted manpages      </B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# manview.sh: Formats the source of a man page for viewing.   3&nbsp;   4&nbsp;#  This script is useful when writing man page source.   5&nbsp;#  It lets you look at the intermediate results on the fly   6&nbsp;#+ while working on it.   7&nbsp;   8&nbsp;E_WRONGARGS=65   9&nbsp;  10&nbsp;if [ -z "$1" ]  11&nbsp;then  12&nbsp;  echo "Usage: `basename $0` filename"  13&nbsp;  exit $E_WRONGARGS  14&nbsp;fi  15&nbsp;  16&nbsp;# ---------------------------  17&nbsp;groff -Tascii -man $1 | less  18&nbsp;# From the man page for groff.  19&nbsp;# ---------------------------  20&nbsp;  21&nbsp;#  If the man page includes tables and/or equations,  22&nbsp;#+ then the above code will barf.  23&nbsp;#  The following line can handle such cases.  24&nbsp;#  25&nbsp;#   gtbl &#60; "$1" | geqn -Tlatin1 | groff -Tlatin1 -mtty-char -man  26&nbsp;#  27&nbsp;#   Thanks, S.C.  28&nbsp;  29&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV></DD><DT><BCLASS="COMMAND">lex</B>, <BCLASS="COMMAND">yacc</B></DT><DD><P>The <BCLASS="COMMAND">lex</B> lexical analyzer produces	      programs for pattern matching. This

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -