unix linux grep and copy

log file how to copy whole content

zgrep -C20 '1234' 1234.log.gz

above gave lot of results in unix screen

how to copy whole page and paste into a text file on my C drive of the windows laptop through which i am connecting to unix box using putty?


also

i see all results like

0123456
9123488

etc

which i do not want

i want complete word search of 1234 only
how to achieve it
please advise
LVL 7
gudii9Asked:
Who is Participating?
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
Use plink instead of PuTTY / WinSCP (this has been suggested to you before I believe).

plink linuxhost -l linuxuser zgrep -C20 '1234' 1234.log.gz > c:\folder\output.txt

Open in new window

Run the above command and post any errors you get back here.
0
 
nociSoftware EngineerCommented:
what is the separator before and after 1234? if it is a space then try

zgrep  -C20 ' 1234 ' 1234.log.gz >output.txt

then you can download the output.txt using WinSCP
0
 
gudii9Author Commented:
if i do not know separator can i still do whole word search?

then you can download the output.txt using WinSCP
i want just search results to a text file not complete log file?
how to do it?
0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
nociConnect With a Mentor Software EngineerCommented:
No the concept of "word" requires a boundary condition for when something is a word.
In my example i used a space, but it can be space / tab or colon (any character not part of a word) ... searching for groupid's in /etc/passwd requires a regex  like ':[0-9]+:500:'    when searching for group 500 (the number in front is the uid in this case it serves as anchor to not match a directory with 500 or a user with id =500

the search string used by grep is called a regular expression, or regex for short.
if you want extended regex's then zegrep might be a better tool.


the '>output.txt'   will send the data to the file named output.txt  which will still reside on the linux system.

>>file appends to a file
<file uses file as standard input.

btw. the >, >> & < are handled by the shell and there should be NO " or ' around them. (that will cause them to be passed to the program, grep will respond with some error about file not found.
0
 
gudii9Author Commented:
log file how to copy whole content
if i have to copy whole content of log file how to copy from putty so that i can paste into windows laptop notepd of my laptop or to outlook email etc
0
 
serialbandConnect With a Mentor Commented:
That's not what you would do in putty.  There's a buffer limit and some log files will exceed that.  You should have pscp.exe or winscp and use it to copy the file from Linux to Windows.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.