-1

I have a grep command like below

zgrep '123_ERROR' xyz.gz

I got lot of huge results where I cannot see top part.

So what is best way to see entire result

how to export results to a file

zgrep '123_ERROR' xyz.gz>>/home/test/testfile.txt

i used above command but i do not seem to have permission to create testfile.txt

how to create above file in one other server whose ip is say 111.1.111.111

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • Hi an welcome to StackExchange. Unfortunately, it is very unclear what you're asking. Please edit your question to show exactly what you're trying to do (input and expected output), and where you are stuck. Also, to see the 'complete' output, you can just pipe zgrep into less or more. – Panki Mar 01 '19 at 14:22
  • I don't know why the IP would affect this. You've tried to write to a file /home/test/testfile.txt Unless your current user is called test you probably don't have access to do this. You can easily reference your own home directory with ~. Eg: zgrep '123_ERROR' xyz.gz ~/testfile.txt – Philip Couling Mar 01 '19 at 14:30

1 Answers1

0

If you wish to do that remotely you can do it this way:

ssh 111.1.111.111 zgrep '123_ERROR' xyz.gz | less

or

ssh 111.1.111.111 zgrep '123_ERROR' xyz.gz \| less

The first command greps results and sends back to you while less is invoced by your host.

The second command does everything on the remote server (the pipe is sent to the other end).

To be precise if you wish to store the output on your computer you could run:

ssh 111.1.111.111 zgrep '123_ERROR' xyz.gz >> local_file
Szczad
  • 161