[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20605: Grep command

From: Eric Blake
Subject: bug#20605: Grep command
Date: Mon, 18 May 2015 20:17:13 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 05/18/2015 11:28 AM, Lakshmana Rao Adabala, Shanmukha wrote:
> Hi Team,
> I would like to know how to get the grep output in the same order.
> For example:
> I am using the following order :  04A2,17F5,04A4
> [cid:image001.png@01D091AF.B34719B0]

Screenshots are hard to parse; it's better to paste actual screen text

It looks like you are using Windows, due to the unusual quoting
paradigms used on the command line:

address@hidden:~> cat 852* | grep -E ""04A4"|"17F5"|"04A2""

On a Unix system, the quoting would be:
cat 852* | grep -E "04A4|17F5|04A2"

> I am expecting output in the following order.
> 04A2
> 17F5
> 04A4

It sounds like you were hoping that grep would make three passes over
your input stream (the concatenated 852* files) - first outputting all
matches to the pattern 04A4, then all matches to the pattern 17F5, then
all matches to the pattern 04A2.  But that's not how grep works.  It
makes a single pass over your input, and for each line, it checks all
alternations within the pattern at once.

> But I am getting the output in the below order
> 04A2
> 04A4
> 17F5

Which means that the first line that matched is one that matched your
third alternative in the single pattern.

> Please let me if any additional switches to use.

The only way to get output in a particular order is to do three separate
passes of grep, on one non-alternating pattern each, rather than one
pass with a three-alternation pattern.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]