LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   cat [file] | grep --- trouble (https://www.linuxquestions.org/questions/linux-general-1/cat-%5Bfile%5D-%7C-grep-trouble-423436/)

bob_man_uk 03-10-2006 04:31 AM

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

spooon 03-10-2006 04:59 AM

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?

jlliagre 03-10-2006 05:08 AM

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 "<>".

bob_man_uk 03-10-2006 05:12 AM

seem to have it now, i havent changed the code or anything, hmm,

thanks anyway

Matty G

bob_man_uk 03-10-2006 05:15 AM

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

sambyte 03-10-2006 05:21 AM

Hi,
pls try out this command and see if it answers your query

# cat [logfile] | grep --color "[<]"

Pls see if it works or not....

bob_man_uk 03-10-2006 05:25 AM

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?

bob_man_uk 03-10-2006 05:27 AM

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

:p

jlliagre 03-10-2006 05:39 AM

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

jschiwal 03-10-2006 05:40 AM

You can grep then use tail to get the last 100 entries for a person.
grep "<bob>" logfile | tail -n 100

bob_man_uk 03-10-2006 05:42 AM

ahh, switch them round...

i see, thats how it is, is it?

excelent, thanks guys.

EDIT - i get this

grep: writing output: Invalid argument

jlliagre 03-10-2006 05:56 AM

You got this error while running which command ?

bob_man_uk 03-10-2006 06:05 AM

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


All times are GMT -5. The time now is 04:56 PM.