SED navigation bar go to SED home page go to Dataplot home page go to NIST home page SED Home Page SED Staff SED Projects SED Products and Publications Search SED Pages
Dataplot Vol 1 Vol 2

GREP

Name:
    GREP
Type:
    Support Command
Purpose:
    This command searches one or more files for a specified string using an operating system specific command.
Description:
    This command uses an operating system command to search one or more files for a specified string.

    For Unix/Linux/MacOS systems, the GREP command issues a

      grep ....

    command to the operating system.

    For Windows systems, the GREP command issues a

      FINDSTR ....

    command to the operating system.

    The string that follows the GREP on the command line is passed to the operating system as is. Dataplot does no error checking of this string.

    This is a system dependent command. It is currently supported for Unix/Linux/MacOS and Windows platforms.

Syntax:
    GREP <str> <file-list>
    where <str> is a string to be matched;
    and <file-list> is a string specifying the files to search.

    If <str> contains spaces, it should be enclosed in quotes.

Examples:
    GREP FIT *.DP
    GREP RESSD *.OUT
    GREP FIT *.DP > FIT_COMMANDS.OUT
Note:
    The GREP capability can be implemented by direct use of the SYSTEM command. For example, under Linux do something like

      system grep fit *.dp

    The motivation for adding this as a separate command is to allow the capability to be implemented in an operating system independent way. This can be useful when writing general purpose macros that may be used on different operating systems.

Note:
    The Dataplot SEARCH command can also be used to search files.

    The SEARCH command has the advantage that it can find files in the Dataplot directories without specifying the full path name and supports a few special keywords for a few specific files. The GREP command has the advantage that it can search multiple files and you can use wild cards in specifying the file names to search. The GREP command is also not limited to printing a maximum of 80 characters for matching lines.

Note:
    Both the Linux grep command and the Windows FINDSTR commands support a number of different options for displaying the output. A few of these are supported as follows.

    By default, the search will not be case sensitive. To specify a case sensitive search, enter the command

      SET GREP CASE NOIGNORE

    To reset the default of case insenstive search, enter the command

      SET GREP CASE IGNORE

    This adds an "/I" option under Windows and a "-i" option under Linux.

    If you specify a directory name to search and you want the files in that directory to be searched, enter the command

      SET GREP RECURSIVE ON

    To reset the default of no recursive search, enter the command

      SET GREP RECURSIVE OFF

    This adds a "/S" option under Windows and a "-r" option under Linux.

    By default, the line number in the file where a match is found will be included in the output. If you want to suppress the line number, enter the command

      SET GREP LINE NUMBERS OFF

    To reset the default of including the line numbers, enter the command

      SET GREP LINE NUMBERS ON

    This adds a "/N" option under Windows and a "-n" option under Linux.

    If you only want to return lines that match exactly, enter the command

      SET GREP EXACT MATCH ON

    To reset the default of not requiring an exact line match, enter the command

      SET GREP EXACT MATCH OFF

    This adds a "/X" option under Windows and a "-x" option under Linux.

    If you want to return lines that do not match, then enter the command

      SET GREP NO MATCH ON

    To reset the default of not requiring an exact line match, enter the command

      SET GREP NO MATCH OFF

    This adds a "/V" option under Windows and a "-v" option under Linux.

    If you want to only print the file name where a match is found, enter the command

      SET GREP FILE NAME ONLY ON

    To reset the default of including the specific lines in the file that match, enter the command

      SET GREP FILE NAME ONLY OFF

    This adds a "/M" option under Windows and a "-l" option under Linux.

    If you want to use options not supported by one of the above SET commands, you can enter them manually. For example, under Linux you can do something like

      grep -w FIT *.DP

    The "-w" match will only match FIT where FIT is a complete word in the file.

Note:
    If you would like to save the output of the GREP command to a file there are two ways to do it.

    The first way is to use the CAPTURE command. For example

      CAPTURE GREP grep.out
      GREP FIT *.DP *.TXT
      END OF CAPTURE

    Alternativey, you can use the ">" syntax at the end of the command. For example

      GREP FIT *.DP *.TXT > grep.out
Note:
    File names are case sensitive on Unix/Linux/MacOS file systems. For this reason, case is preserved in passing the file name to the operating system.
Default:
    None
Synonyms:
    FINDSTR is a synonym for GREP
Related Commands:
    SEARCH = Search a file for a given string.
    CAT = Display the contents of a file.
    SYSTEM = Enter an operating system command within a Dataplot session.
    CD = Change the current working directory.
    PWD = Retrieve the current working directory.
    MKDIR = Create a new directory
    RM = Delete one or more files.
    DIR = List the contents of a directory.
Applications:
    Interactive Usage
Implementation Date:
    2019/09
Program:
     
    grep FIT  *.DP *.TXT  macros/*.DP macros/*.TXT
        

Privacy Policy/Security Notice
Disclaimer | FOIA

NIST is an agency of the U.S. Commerce Department.

Date created: 09/13/2019
Last updated: 09/13/2019

Please email comments on this WWW page to alan.heckert@nist.gov.