<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FRegular_Expressions%2FGrep</id>
		<title>Java/Regular Expressions/Grep - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FRegular_Expressions%2FGrep"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Regular_Expressions/Grep&amp;action=history"/>
		<updated>2026-04-07T20:26:17Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Regular_Expressions/Grep&amp;diff=6023&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Regular_Expressions/Grep&amp;diff=6023&amp;oldid=prev"/>
				<updated>2010-06-01T06:00:49Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:00, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Regular_Expressions/Grep&amp;diff=6022&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Regular_Expressions/Grep&amp;diff=6022&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A command-line grep-like program. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.regex.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
/** A command-line grep-like program. No options, but takes a pattern&lt;br /&gt;
 * and an arbitrary list of text files.&lt;br /&gt;
 */&lt;br /&gt;
public class Grep1 {&lt;br /&gt;
  /** The pattern we&amp;quot;re looking for */&lt;br /&gt;
  protected Pattern pattern;&lt;br /&gt;
  /** The matcher for this pattern */&lt;br /&gt;
  protected Matcher matcher;&lt;br /&gt;
  /** Main will make a Grep object for the pattern, and run it&lt;br /&gt;
   * on all input files listed in argv.&lt;br /&gt;
   */&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    if (argv.length &amp;lt; 1) {&lt;br /&gt;
        System.err.println(&amp;quot;Usage: Grep1 pattern [filename]&amp;quot;);&lt;br /&gt;
        System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    Grep1 pg = new Grep1(argv[0]);&lt;br /&gt;
    if (argv.length == 1)&lt;br /&gt;
      pg.process(new BufferedReader(new InputStreamReader(System.in)),&lt;br /&gt;
        &amp;quot;(standard input)&amp;quot;, false);&lt;br /&gt;
    else&lt;br /&gt;
      for (int i=1; i&amp;lt;argv.length; i++) {&lt;br /&gt;
        pg.process(new BufferedReader(new FileReader(argv[i])),&lt;br /&gt;
          argv[i], true);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
  /** Construct a Grep1 program */&lt;br /&gt;
  public Grep1(String patt) {&lt;br /&gt;
    pattern = Pattern.rupile(patt);&lt;br /&gt;
    matcher = pattern.matcher(&amp;quot;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  /** Do the work of scanning one file&lt;br /&gt;
   * @param ifile BufferedReader object already open&lt;br /&gt;
   * @param fileName String Name of the input file&lt;br /&gt;
   * @param printFileName Boolean - true to print filename&lt;br /&gt;
   * before lines that match.&lt;br /&gt;
   */&lt;br /&gt;
  public void process(&lt;br /&gt;
    BufferedReader inputFile, String fileName, boolean printFileName) {&lt;br /&gt;
    String inputLine;&lt;br /&gt;
    try {&lt;br /&gt;
      while ((inputLine = inputFile.readLine()) != null) {&lt;br /&gt;
        matcher.reset(inputLine);&lt;br /&gt;
        if (matcher.lookingAt()) {&lt;br /&gt;
          if (printFileName) {&lt;br /&gt;
            System.out.print(fileName + &amp;quot;: &amp;quot;);&lt;br /&gt;
          }&lt;br /&gt;
          System.out.println(inputLine);&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      inputFile.close();&lt;br /&gt;
    } catch (IOException e) { System.err.println(e); }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== A grep-like program using NIO but NOT LINE BASED. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import java.nio.*;&lt;br /&gt;
import java.nio.channels.*;&lt;br /&gt;
import java.nio.charset.*;&lt;br /&gt;
import java.util.regex.*;&lt;br /&gt;
/** A grep-like program using NIO but NOT LINE BASED.&lt;br /&gt;
 * Pattern and file name(s) must be on command line.&lt;br /&gt;
 */&lt;br /&gt;
public class GrepNIO {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    if (args.length &amp;lt; 2) {&lt;br /&gt;
      System.err.println(&amp;quot;Usage: GrepNIO patt file [...]&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    Pattern p=Pattern.rupile(args[0]);&lt;br /&gt;
    for (int i=1; i&amp;lt;args.length; i++)&lt;br /&gt;
      process(p, args[i]);&lt;br /&gt;
  }&lt;br /&gt;
  static void process(Pattern pattern, String fileName) throws IOException {&lt;br /&gt;
    // Get a FileChannel from the given file.&lt;br /&gt;
    FileChannel fc = new FileInputStream(fileName).getChannel();&lt;br /&gt;
    // Map the file&amp;quot;s content&lt;br /&gt;
    ByteBuffer buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());&lt;br /&gt;
    // Decode ByteBuffer into CharBuffer&lt;br /&gt;
    CharBuffer cbuf =&lt;br /&gt;
      Charset.forName(&amp;quot;ISO-8859-1&amp;quot;).newDecoder().decode(buf);&lt;br /&gt;
    Matcher m = pattern.matcher(cbuf);&lt;br /&gt;
    while (m.find()) {&lt;br /&gt;
      System.out.println(m.group(0));&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Another Grep  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
// Sun Microsystems Example Code @(#)Grep.java 1.1 01/05/10&lt;br /&gt;
//Search a list of files for lines that match a given regular-expression&lt;br /&gt;
//pattern. Demonstrates NIO mapped byte buffers, charsets, and regular&lt;br /&gt;
//expressions.&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.nio.CharBuffer;&lt;br /&gt;
import java.nio.MappedByteBuffer;&lt;br /&gt;
import java.nio.channels.FileChannel;&lt;br /&gt;
import java.nio.charset.Charset;&lt;br /&gt;
import java.nio.charset.CharsetDecoder;&lt;br /&gt;
import java.util.regex.Matcher;&lt;br /&gt;
import java.util.regex.Pattern;&lt;br /&gt;
import java.util.regex.PatternSyntaxException;&lt;br /&gt;
public class GrepSun {&lt;br /&gt;
  // Charset and decoder for ISO-8859-15&lt;br /&gt;
  private static Charset charset = Charset.forName(&amp;quot;ISO-8859-15&amp;quot;);&lt;br /&gt;
  private static CharsetDecoder decoder = charset.newDecoder();&lt;br /&gt;
  // Pattern used to parse lines&lt;br /&gt;
  private static Pattern linePattern = Pattern.rupile(&amp;quot;.*\r?\n&amp;quot;);&lt;br /&gt;
  // The input pattern that we&amp;quot;re looking for&lt;br /&gt;
  private static Pattern pattern;&lt;br /&gt;
  // Compile the pattern from the command line&lt;br /&gt;
  //&lt;br /&gt;
  private static void compile(String pat) {&lt;br /&gt;
    try {&lt;br /&gt;
      pattern = Pattern.rupile(pat);&lt;br /&gt;
    } catch (PatternSyntaxException x) {&lt;br /&gt;
      System.err.println(x.getMessage());&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // Use the linePattern to break the given CharBuffer into lines, applying&lt;br /&gt;
  // the input pattern to each line to see if we have a match&lt;br /&gt;
  //&lt;br /&gt;
  private static void grep(File f, CharBuffer cb) {&lt;br /&gt;
    Matcher lm = linePattern.matcher(cb); // Line matcher&lt;br /&gt;
    Matcher pm = null; // Pattern matcher&lt;br /&gt;
    int lines = 0;&lt;br /&gt;
    while (lm.find()) {&lt;br /&gt;
      lines++;&lt;br /&gt;
      CharSequence cs = lm.group(); // The current line&lt;br /&gt;
      if (pm == null)&lt;br /&gt;
        pm = pattern.matcher(cs);&lt;br /&gt;
      else&lt;br /&gt;
        pm.reset(cs);&lt;br /&gt;
      if (pm.find())&lt;br /&gt;
        System.out.print(f + &amp;quot;:&amp;quot; + lines + &amp;quot;:&amp;quot; + cs);&lt;br /&gt;
      if (lm.end() == cb.limit())&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  // Search for occurrences of the input pattern in the given file&lt;br /&gt;
  //&lt;br /&gt;
  private static void grep(File f) throws IOException {&lt;br /&gt;
    // Open the file and then get a channel from the stream&lt;br /&gt;
    FileInputStream fis = new FileInputStream(f);&lt;br /&gt;
    FileChannel fc = fis.getChannel();&lt;br /&gt;
    // Get the file&amp;quot;s size and then map it into memory&lt;br /&gt;
    int sz = (int) fc.size();&lt;br /&gt;
    MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);&lt;br /&gt;
    // Decode the file into a char buffer&lt;br /&gt;
    CharBuffer cb = decoder.decode(bb);&lt;br /&gt;
    // Perform the search&lt;br /&gt;
    grep(f, cb);&lt;br /&gt;
    // Close the channel and the stream&lt;br /&gt;
    fc.close();&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    if (args.length &amp;lt; 2) {&lt;br /&gt;
      System.err.println(&amp;quot;Usage: java Grep pattern file...&amp;quot;);&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    compile(args[0]);&lt;br /&gt;
    for (int i = 1; i &amp;lt; args.length; i++) {&lt;br /&gt;
      File f = new File(args[i]);&lt;br /&gt;
      try {&lt;br /&gt;
        grep(f);&lt;br /&gt;
      } catch (IOException x) {&lt;br /&gt;
        System.err.println(f + &amp;quot;: &amp;quot; + x);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Grep0 - Match lines from stdin against the pattern on the command line. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import java.util.regex.*;&lt;br /&gt;
/** Grep0 - Match lines from stdin against the pattern on the command line.&lt;br /&gt;
 */&lt;br /&gt;
public class Grep0 {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    BufferedReader is =&lt;br /&gt;
      new BufferedReader(new InputStreamReader(System.in));&lt;br /&gt;
    if (args.length != 1) {&lt;br /&gt;
      System.err.println(&amp;quot;Usage: MatchLines pattern&amp;quot;);&lt;br /&gt;
      System.exit(1);&lt;br /&gt;
    }&lt;br /&gt;
    Pattern patt = Pattern.rupile(args[0]);&lt;br /&gt;
    Matcher matcher = patt.matcher(&amp;quot;&amp;quot;);&lt;br /&gt;
    String line = null;&lt;br /&gt;
    while ((line = is.readLine()) != null) {&lt;br /&gt;
      matcher.reset(line);&lt;br /&gt;
      if (matcher.find()) {&lt;br /&gt;
        System.out.println(&amp;quot;MATCH: &amp;quot; + line);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>