0

Hi I stuck with some script that is doing some text filtering

script is counting occurrences by doing:

 cat file | sort | grep -v "^$" | uniq -c |  sort -nr | head -20

Is not obvious for me how will grep -v "^$" works. As I am understanding -v which is invert the sense of matching, inverting pattern with begging of line and end of line is not obvious for me.

I was trying few examples but is not clear to understand for me how it works (i.e. it filter spaces but not carriage returns)

Mazeryt
  • 677
  • 1
  • 13
  • 32
  • This might help: [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/3776858) – Cyrus Jun 24 '17 at 15:36

1 Answers1

1

It will just get rid of empty lines. "^$" matches lines that start and end without anything in between the start and end.

Tonmoy Roy
  • 61
  • 4