LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need a linux command (https://www.linuxquestions.org/questions/linux-newbie-8/need-a-linux-command-520100/)

Volcano 01-17-2007 05:39 AM

need a linux command
 
i have a big log file in a directory.

in this log file , there is line which contains keyword "XML MESSAGE".

i want to print -5 lines above and +5 lines below (including that line also) to that line.

whats the linux command for this ?

avallach 01-17-2007 05:43 AM

Code:

cat your_log_file | grep XML MESSAGE -A 5 -B 5

Volcano 01-17-2007 05:50 AM

Quote:

Originally Posted by avallach
Code:

cat your_log_file | grep XML MESSAGE -A 5 -B 5

i guess you meant

cat your_log_file | grep "XML MESSAGE" -A 5 -B 5 .

please note "XML MESSAGE" is a keyword , a fixed string

colucix 01-17-2007 05:52 AM

Quote:

Originally Posted by avallach
Code:

cat your_log_file | grep XML MESSAGE -A 5 -B 5

Good the avallach solution! Just a note: you have to double quote the "XML MESSAGE" or escape the blank space:

Code:

grep XML\ MESSAGE -A5 -B5 your_log_file

Volcano 01-17-2007 05:55 AM

Quote:

Originally Posted by colucix
Good the avallach solution! Just a note: you have to double quote the "XML MESSAGE" or escape the blank space:

Code:

grep XML\ MESSAGE -A5 -B5 your_log_file



not working !

i got the following error msg :

grep: can't open -A
grep: can't open 5
grep: can't open -B
grep: can't open 5



i used this ..

vi mylogfile.log | grep "Xml To Publish : " -A 5 -B 5

whats wrong here ?

Volcano 01-17-2007 06:03 AM

Quote:

Originally Posted by Volcano
not working !

i got the following error msg :

grep: can't open -A
grep: can't open 5
grep: can't open -B
grep: can't open 5



i used this ..

vi mylogfile.log | grep "Xml To Publish : " -A 5 -B 5

whats wrong here ?

let me know whether i have done any mistake ...why its not working ?

colucix 01-17-2007 06:09 AM

It works for me, using grep-2.5.1-52.2 on FC5.

Quote:

vi mylogfile.log | grep "Xml To Publish : " -A 5 -B 5
You cannot pipe the output of vi command, because vi is an interactive editor. Use cat instead, as in the examples above.

pwc101 01-17-2007 06:11 AM

You need to use cat, not vi, to display the contents of the file. This:
Code:

vi mylogfile.log | grep "Xml To Publish : " -A 5 -B 5
needs to be
Code:

cat mylogfile.log | grep "Xml To Publish : " -A 5 -B 5

Volcano 01-17-2007 06:14 AM

Quote:

Originally Posted by pwc101
You need to use cat, not vi, to display the contents of the file. This:
Code:

vi mylogfile.log | grep "Xml To Publish : " -A 5 -B 5
needs to be
Code:

cat mylogfile.log | grep "Xml To Publish : " -A 5 -B 5

still not working .

see below..

server_dir> cat mylogfile.log | grep "Xml To Publish : " -A 5 -B 5
grep: can't open -A
grep: can't open 5
grep: can't open -B
grep: can't open 5

Volcano 01-17-2007 06:15 AM

Quote:

Originally Posted by Volcano
still not working .

see below..

server_dir> cat mylogfile.log | grep "Xml To Publish : " -A 5 -B 5
grep: can't open -A
grep: can't open 5
grep: can't open -B
grep: can't open 5

is this command working in your machine ?

Volcano 01-17-2007 06:16 AM

do you have any other alternative which could solve the same purpose ?

colucix 01-17-2007 06:20 AM

It works quite well! Which version of grep do you have?

Volcano 01-17-2007 06:23 AM

Quote:

Originally Posted by colucix
It works quite well! Which version of grep do you have?

whats the command to check that ?

please tell me the command ..i'll check and post it .

can you tell any other alternative which could solve my problem ?

colucix 01-17-2007 06:34 AM

Quote:

Originally Posted by Volcano
whats the command to check that ?

grep -V
or
grep --version

Quote:

can you tell any other alternative which could solve my problem ?
Not a one-line command! I have to think for a while, however...

Volcano 01-17-2007 06:48 AM

Quote:

Originally Posted by colucix
grep -V
or
grep --version



Not a one-line command! I have to think for a while, however...


i found

grep -V
grep: illegal option -- V
Usage: grep -hblcnsviw pattern file . . .


i believe this is a unix system ...because tail command works fine in this system.....i work via telnet only....do you think ,..its a unix box ?

if so whats the equivalent command in unix which could solve my purpose ?


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