Searching file contents

The grep command has many options for text and pattern matching in files. It can be used with one or more files. Regular expression pattern matching is an excellent feature and can be used for a wide variety of requirements.

root@hostname:directory# grep -n software /var/easypush/web_server/license.txt
60:Agreement. The License Agreement does not affect any software except the
98:The Product is provided as free software, in the hope that it will be
root@experiment:/var/easypush/web_server# grep -n source license.txt 
4:SERVER, its source code, documentation, and executable files, hereinafter
21:exception of specific copyrights as noted in the individual source files.
27:Executable") and as a package of source files, the "Product Sources".
43:You do not need to provide the source code for the Product as part of your
47:1.  Provide the source code for Product modules that you use, and include
64:You may modify any part of the Product, including sources and documentation,
67:You must clearly indicate any modifications at the start of each source
68:file. The user of any modified Product code must know that the source file
74:include a credit at the start of each source file indicating the original
75:authorship and source of the code, and a statement of copyright as follows:
83:from original or modified copies of the product source code. The License, in

The above command searches for instances of the text source in the file /var/easypush/web_server/license.txt. You can use a regular expression depending on your need. egrep can be used for extended regular expression search:

root@hostname:directory# egrep -n '(agree|Agree)ment' /var/easypush/web_server/license.txt 
3:This license agreement covers your use of the iMatix Corporation XITAMI WEB
8:distribute it according to this following License Agreement. If you do not
13:This License Agreement covers the current version of The Product. iMatix
14:Corporation reserves the right to modify the terms of this License Agreement
38:The Product Sources fall under the License Agreement for the iMatix SMT
45:License Agreement:
48:    this License Agreement, or
51:    License Agreement, or
60:Agreement. The License Agreement does not affect any software except the
62:itself fall under the License Agreement.
65:except this License Agreement, which you may not modify.
73:does not fall under the Product License Agreement directly, but you must
 
help/command-line/searching-file-contents.txt · Last modified: 2009/07/24 02:53 by gaurav     Back to top