grep -l prints the file names so you can process them with xargs.
But xargs has a problem with space characters in file names. find -exec handles spaces well: grep -q suppresses output; the exit status decides on the following.
Probably all find versions cannot chain {} + queues so there is a need for a slower {} \;.
Many GNU utilities allow 0-byte terminated lines, so the following is fast and correct:
This User Gave Thanks to MadeInGermany For This Post:
Hi,
I would like to ask if there is any method to grep a chuck of lines based on the latest file in a directory.
E.g
Latest file in the directory:
Line 1: 532243
Line 2: 123456
Line 3: 334566
Line 4: 44567545
I wanted to grep all the line after line 2 i.e. Line 3 and line 4 and... (5 Replies)
I have to grep on a few words in a file and then display the line containing those words and the line above it.
For ex -
File1.txt contains...
abc xyz abc
This is a test
Test successful
abc xyz abc
Just a test
Test successful
I find the words 'Test successful' in the file... (6 Replies)
Hi Friends,
I have a file which has many of the statements like below
******** MAKING > noun1 < cg_all
statements
statements
statements
********* MAKING > noun2 < cg_all
statements
statements
statements
********* MAKING > noun3 < all
statements
statements
statements
I would... (3 Replies)
Hi,
I have one file, say file 1, that has data like below where 19900107 is the date,
19900107 12 144 129 0.7380047
19900108 12 168 129 0.3149017
19900109 12 192 129 3.2766666E-02
... (3 Replies)
Sample File
abc
xyz
def
abc
ggh
abc
xyz
I just created a sample file above to show what I need. I need to grep two lines. e.g abc and xyz(only if they are one after the other) so output would be
abc
xyz
abc
xyz
(note abc followed by ggh line would not come out in the output). I... (9 Replies)
Hello. How does one grep lines in a file that have only one field?
AAA BBB CCC
DDD
AAA CCC
Is is possible to grep "DDD" becuase it has only one field?
Thanks.
---------- Post updated at 08:03 PM ---------- Previous update was at 07:25 PM ----------
I found it, thank you!
awk 'NF... (2 Replies)
Hi guys,
This is probably very easy but I've no idea how to pull this out.
Basically, I need to find errors into a very large logfile. When you grep the ID, the output is like this:
+- Type: 799911 Code: Ret: 22728954 Mand: X Def: Des: UserDes: SeqNo: 2
+- Type: 799911 Code: Ret:... (5 Replies)
Hi all,
I have two files.
File A looks like this:
abkhasian com|hum
accent com|com|com|com|sta
acceptation act|com|sta
adventures com|hum
adversity com|hum|hum
and File B looks like this:
adventure
adventures
adversary
Adverse
adversity
I want to print those lines in File A... (9 Replies)
Discussion started by: owwow14
9 Replies
LEARN ABOUT ULTRIX
grep
grep(1) General Commands Manual grep(1)Name
grep, egrep, fgrep - search file for regular expression
Syntax
grep [option...] expression [file...]
egrep [option...] [expression] [file...]
fgrep [option...] [strings] [file]
Description
Commands of the family search the input files (standard input default) for lines matching a pattern. Normally, each line found is copied
to the standard output.
The command patterns are limited regular expressions in the style of which uses a compact nondeterministic algorithm. The command patterns
are full regular expressions. The command uses a fast deterministic algorithm that sometimes needs exponential space. The command pat-
terns are fixed strings. The command is fast and compact.
In all cases the file name is shown if there is more than one input file. Take care when using the characters $ * [ ^ | ( ) and in the
expression because they are also meaningful to the Shell. It is safest to enclose the entire expression argument in single quotes ' '.
The command searches for lines that contain one of the (new line-separated) strings.
The command accepts extended regular expressions. In the following description `character' excludes new line:
A followed by a single character other than new line matches that character.
The character ^ matches the beginning of a line.
The character $ matches the end of a line.
A . (dot) matches any character.
A single character not otherwise endowed with special meaning matches that character.
A string enclosed in brackets [] matches any single character from the string. Ranges of ASCII character codes may be abbreviated
as in `a-z0-9'. A ] may occur only as the first character of the string. A literal - must be placed where it can't be mistaken as
a range indicator.
A regular expression followed by an * (asterisk) matches a sequence of 0 or more matches of the regular expression. A regular
expression followed by a + (plus) matches a sequence of 1 or more matches of the regular expression. A regular expression followed
by a ? (question mark) matches a sequence of 0 or 1 matches of the regular expression.
Two regular expressions concatenated match a match of the first followed by a match of the second.
Two regular expressions separated by | or new line match either a match for the first or a match for the second.
A regular expression enclosed in parentheses matches a match for the regular expression.
The order of precedence of operators at the same parenthesis level is the following: [], then *+?, then concatenation, then | and new
line.
Options-b Precedes each output line with its block number. This is sometimes useful in locating disk block numbers by context.
-c Produces count of matching lines only.
-e expression
Uses next argument as expression that begins with a minus (-).
-f file Takes regular expression (egrep) or string list (fgrep) from file.
-i Considers upper and lowercase letter identical in making comparisons and only).
-l Lists files with matching lines only once, separated by a new line.
-n Precedes each matching line with its line number.
-s Silent mode and nothing is printed (except error messages). This is useful for checking the error status (see DIAGNOSTICS).
-v Displays all lines that do not match specified expression.
-w Searches for an expression as for a word (as if surrounded by `<' and `>'). For further information, see only.
-x Prints exact lines matched in their entirety only).
Restrictions
Lines are limited to 256 characters; longer lines are truncated.
Diagnostics
Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files.
See Alsoex(1), sed(1), sh(1)grep(1)