Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-10-2006, 04:31 AM
|
#1
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Rep:
|
cat [file] | grep --- trouble
hey all,
quick little problem here, i have a log from my IRC channel, i want to use CAT on it for specific users for example
cat [logfile] | grep "username"
but the problem im getting is that the usernames are wrapped in < >'s
what would i need to do to get cat or grep to ignore the < >'s and just treat them as part of a word?
ive tried wrapping `word` "word" and 'word' and I still get nothing.
any help is appreciated.
Matty G
|
|
|
|
03-10-2006, 04:59 AM
|
#2
|
|
Senior Member
Registered: Aug 2005
Posts: 1,755
Rep:
|
Quote:
|
Originally Posted by bob_man_uk
but the problem im getting is that the usernames are wrapped in < >'s
what would i need to do to get cat or grep to ignore the < >'s and just treat them as part of a word?
|
I don't get it; isn't this what grep usually does? Can you give an example and show us the exact commands?
|
|
|
|
03-10-2006, 05:08 AM
|
#3
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Quote:
|
Originally Posted by bob_man_uk
Code:
cat [logfile] | grep "username"
|
can be simplified to
Code:
grep username logfile
and as already stated, doesn't choke on "<>".
|
|
|
|
03-10-2006, 05:12 AM
|
#4
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
seem to have it now, i havent changed the code or anything, hmm,
thanks anyway
Matty G
|
|
|
|
03-10-2006, 05:15 AM
|
#5
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
Quote:
|
Originally Posted by jlliagre
can be simplified to
Code:
grep username logfile
and as already stated, doesn't choke on "<>".
|
but that would search for the username on every line,
i only want to bring back lines by specific users
E.G.
grep for bobman brings back sum 400 lines
grep for <bobman> brings back some 200 lines +/- 2 or 3 lines where someone will have quoted my own words,
got it sorted now anyway, i think i may have been telling cat to look at the wrong log file,
thanks again
Matty G
|
|
|
|
03-10-2006, 05:21 AM
|
#6
|
|
Member
Registered: Feb 2006
Distribution: Redhat 9
Posts: 38
Rep:
|
Hi,
pls try out this command and see if it answers your query
# cat [logfile] | grep --color "[<]"
Pls see if it works or not....
|
|
|
|
03-10-2006, 05:25 AM
|
#7
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
ok, sorry for the 3rd post but I have another question
I want to tail this log file and find the last 100 lines a user wrote (using <>'s again im afraid)
if i use
tail -100 "logfile" | grep "<bobman>"
it only brings back <bobman> from the last 100 lines, which thinking about it, is what it should do, what other ways should i go about pulling the last 100 lines of <bobman> from the log file?
Last edited by bob_man_uk; 03-10-2006 at 05:28 AM.
|
|
|
|
03-10-2006, 05:27 AM
|
#8
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
Quote:
|
Originally Posted by sambyte
Hi,
pls try out this command and see if it answers your query
# cat [logfile] | grep --color "[<]"
Pls see if it works or not....
|
yes it works all too well, it pulls every line form the log file,
viva la ctrl+c

|
|
|
|
03-10-2006, 05:39 AM
|
#9
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Quote:
|
Originally Posted by bob_man_uk
ok, sorry for the 3rd post but I have another question
I want to tail this log file and find the last 100 lines a user wrote (using <>'s again im afraid)
if i use
tail -100 "logfile" | grep "<bobman>"
it only brings back <bobman> from the last 100 lines, which thinking about it, is what it should do, what other ways should i go about pulling the last 100 lines of <bobman> from the log file?
|
Try this:
Code:
grep "<bobman>" logfile | tail -100
|
|
|
|
03-10-2006, 05:40 AM
|
#10
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
You can grep then use tail to get the last 100 entries for a person.
grep "<bob>" logfile | tail -n 100
|
|
|
|
03-10-2006, 05:42 AM
|
#11
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
ahh, switch them round...
i see, thats how it is, is it?
excelent, thanks guys.
EDIT - i get this
grep: writing output: Invalid argument
Last edited by bob_man_uk; 03-10-2006 at 05:47 AM.
|
|
|
|
03-10-2006, 05:56 AM
|
#12
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
You got this error while running which command ?
Last edited by jlliagre; 03-10-2006 at 05:59 AM.
|
|
|
|
03-10-2006, 06:05 AM
|
#13
|
|
Member
Registered: Jul 2003
Location: uk
Posts: 80
Original Poster
Rep:
|
I run this
grep "<bob_man>" "#devhardware.GoodChatting.com.log" | tail -n 50
ok, ok i quess i will need to come clean here,
Im using ports of unix tools to do this on my home pc which.... is windows XP,
forget it, i guess i could knife and fork it by
cat logfile | grep username > username.txt
then tail the last 20 lines or something.
thanks all the same.
Matty G
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:07 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|