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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
nociSoftware 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
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

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
serialbandCommented:
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
Gerwin Jansen, EE MVETopic 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Security

From novice to tech pro — start learning today.