can we get sorted grep output
5,409
It is not possible by only using grep
. You have to use another tool e.g. sort
:
$ grep -e apple -e mango *.txt | sort -t: -k2,2
1.txt:apple
3.txt:apple
2.txt:mango
4.txt:mango
Related videos on Youtube
Author by
christopher_bincom
Updated on September 18, 2022Comments
-
christopher_bincom over 1 year
I have same:
1.txt
withapple
written in it,2.txt
withmango
written in it,3.txt
withapple
written in it,4.txt
withmango
written in it.grep -e apple -e mango *.txt
will give result as:1.txt: apple 2.txt: mango 3.txt: apple 4.txt: mango
But I need output as:
1.txt: apple 3.txt: apple 2.txt: mango 4.txt: mango
Is it possible with just
grep
command ? -- without using any other command like sort or so-
clerksx about 9 yearsNo, and even if there was, it would be wrong. Use
sort
. -
jordanm about 9 yearsNo,
grep
does not perform sorting.
-