Search code examples
linuxzcat

Zcat with lines' indexes


How can I see the indexes of lines with zcat? I tried to find a flag of zcat, but didn't find one that show lines' numbers.

Example: My file contains these lines:

Hello everybody!
aaa bbb
aaa Hello

What I want to get from this command:

zcat file | grep Hello

Is:

1 Hello everybody! 
3 aaa Hello

Any ideas? Thanks!


Solution

  • You can use -n flag with grep command in order to view the line number.

    $ zcat hello.zip | grep -n "Hello" 1:Hello everybody! 3:aaa Hello ubuntu14@ubuntu14:~/Public$