Quick GREP Question..

Hey guys,

Something is puzzling me!

I saw someone use the grep in the following way and I'm not sure I understand what it does, and if there's any benefit to using it this way.

Code:
grep X.X.X.X /var/log/log.log | grep -v query

I checked the man file which confirmed that -v is relating to matching non grouping lines (which I'm not sure I fully understand either!) but I don't see any difference in the output of the above command versus the same command without the | grep -v query bit..

Why would you pipe grep into grep unless you were searching for something specific within the search results?

Does query mean something else?


Similar Content



Please Interpret The Meaning Of This Command

Hi ,

Please explain what the below command means ..


Code:
if grep -c -i Y $INIFILE > /dev/null

I know what is the use of grep, it is used for finding a character or string in a file. But i could not understand the above form of grep command.

I am new to linux so this might be a simple question, but please throw some light on it.


Edited

And also please explain why they are creating a file in null in the below command

Code:
cat /dev/null > $DATA_DIR/$DATAFILE

Redirection. Help Pls.

Hello there. Im stuck on a task.

it`s the task:
Search the file 'data' for all of the lines that contain the pattern 'linux'
and put those lines in the file 'matches'.

You entered: grep "linux" date > matches
Please try again.

I tried lots of variants
1) grep linux date > matches
2) grep 'linux' date > matches
3) grep linux date >> matches

May be something`s wrong with grep command?
I just dont get it >.>; it should work fine. Where is my mistake folks?

Exporting Log Data To A File That Matches Stdout

hey guys,

Let's say I want to find out which log files have related ntp information in them. I use cat and grep to search through the files in /var/log and then export that to a file. this is the command...

# cat /var/log/* | grep ntp > /home/log.txt

The file created from this command will not include the directories the log entries are apart of. Why not? For example, if you do this same command without exporting to the /home/log.txt file it will show you in stdout which directory each log entry is in. Hope I'm making sense here. My question is, is there a clever way to export to a file in a way so that the file created is structured exactly like the stdout of the command below?

# cat /var/log/* | grep ntp

Searching For Strings

If there is one Windows XP feature that I greatly miss in Mint, it is the Search Companion.

I have been struggling with 'grep' in order to create something suitable but with limited success. Take the following problem:-

I wish to interrogate the folder home/dell/Documents/Domestic/Recipes, searching for all files containing the word "mushroom" or "mushrooms", ignoring case. (I can manage the latter. )

Each individual file search should terminate at the first instance of a match and move to the next file. (Recursive, yeh?) Only the file names need to be listed and the output should be paged to allow for easier reading of long lists.

Several different types of file may be involved, including .doc, .odt, .txt .pdf, .htm and .rtf. It would be nice to include all of them in one command. (Wild card behaviour in grep is not entirely predictable - at least not for me.) Running a separate grep command for each different file type would be tedious.

A significant difficulty is that, if grep fails with a syntax, or run-time error, it generally reports the fact but it also has a habit of producing no output, perhaps not returning to the command prompt, whilst sitting inviting the user to decide what to do next. What makes this particularly frustrating is that some file types might not be amenable to a grep search. Text in .txt files and, it would appear, .doc files appears to be searchable but I suspect that .odt files might be more problematic. The snag in such circumstances is trying to interpret grep's response. Does a null return mean that no match was found or that the file format cannot be successfully interrogated? Such failure might not be apparent if the associated file names are simply excluded from the output list.

Apart from grep, is there any other software that would do the job? Sadly LibreOffice Writer seems to be lacking in this area.

Using Xargs And Grep In Find Command

I've been using this a lot:

find <directory to start search at> -name "<files to search in>" -type f | xargs grep "<string to search for>"

e.g.

find /usr/include -name "*.h" -type f | xargs grep "#define UINT"

now what if I wanted to output the results to a file?

Log Monitor Shell Script

Hi Guys,

i have requirement for log monitor shell script as per below
a)grep WARNING or EXCEPTION or SEVERE from log file
b) count the grep results
c)send an email notification for grep results

please help me .

thanks,
Arun

Using Awk Print

Hi Linux Guru's

need some a little help regarding on the jboss command that will validate. The command should only echo either "jboss7" or "jboss4"


however in our jboss7 we got also jboss7modules running and it should not be there from the output

[pogi.ako@server2 ~]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}'
jboss7
jbossmodules


using with |tail -1 | head -1
[lemuel.luna@server2 ~]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}' |tail -1 | head -1
jbossmodules


but from other servers I see it has different approach

[pogi.ako@server1 bin]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}'
jbossmodules
jboss7


[pogi.ako@server1 bin]$ rpm -qa | grep jboss | grep -v config | awk -F'-' '{print $3}' |tail -1 | head -1
jboss7


I'm trying to achieve here on on not to include jbossmodules from the output

Grep Is Not Working In RHEL5.3

Hi,

I have Redhat 5.3 running on my machine. But when I am login through putty it gives me below error.
Without running any grep command I get this error on login and the grep command doesn't work.

login as: root
root@IP's password:
Last login: Mon Feb 16 15:27:55 2015 from IP
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/egrep: cannot execute binary file
-bash: /bin/grep: cannot execute binary file
-bash: /bin/grep: cannot execute binary file
[root@bkpdrill ~]# grep MemTotal /proc/meminfo
-bash: /bin/grep: cannot execute binary file

How Can I Grep Variable?

I want to And search grep shell

but It's hard to grep variable


---------------------------------------------------------------
#!/bin/bash


if [ $# -eq 0 ]
then
echo "Ussage: phone searchfor [...searchfor]"
echo "(You didn't tell me what you want to search for )"

else

pass=0
find=""

for idx in $*
do
if [ -n "$idx" ]
then
if [ $pass -eq 0 ]
then
find=$(egrep "$idx" mydata)
pass=1

else

find=$("$find" | grep "$idx")

echo $find
fi
fi

done

if [ -z "$find" ]
then
echo "There is no such thing"
else

echo $find | awk -f display.awk

fi

fi

-----------------------------------------------------

there is one error : command not found

in find=$("$find" | grep "$idx")

how can I grep variable and store it into variable?

What Ftp Server Is Running

in my RHEL 4 server , I want to know what ftp server is running but can't find it.

I tried "ps -ef |grep ftp" but no output , chkconfig --list |grep ftp also no output related to ftp , /etc/rc.d/init.d can't find ftp service , ftp localhost is not allow .

when use FileZilla to connect it , it is ok , the ftp should be running , I tried to use "ps -ef |grep ftp" , it pops the following output , would advise what ftp server is running in server ? thanks

Code:
edp 11027 11026  0 12:39 ?        00:00:00 tcsh -c /usr/libexec/openssh/sftp-server
edp 11037 11027  0 12:39 ?        00:00:00 /usr/libexec/openssh/sftp-server
user   11050  7747  0 12:48 pts/2    00:00:00 grep ftp