GNU bug report logs -
#20605
Grep command
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
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 <at> 01D091AF.B34719B0]
Screenshots are hard to parse; it's better to paste actual screen text
content.
It looks like you are using Windows, due to the unusual quoting
paradigms used on the command line:
service <at> VPLEXCLU2:~> 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
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 10 years and 50 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.