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


Similar Content



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.

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?

How To Search All Sub-directories For A File Or Command Line In A File In Ubuntu?

Hello--

I'm trying to locate a file or a command line in a file on my hard drive. I am running Ubuntu 12.05.4 linux. Is there a grep command that will search the whole tree from root down to all the sub-directories?

Thank You.

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?

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

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?

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

Find Command Fear And Loathing

Its plentiful documentation fails to explain how to use it. After googling all over the world and hunting down examples, it turns out they don't work as the man page indicates if you alter them in the slightest. In fact I know what I want to find, where it is, how to describe it; but the problem is getting find to list that file or those files and moreover making sense of its horrid documentation. It lists too many things. It ignores -prune. It either does nothing or too much. Its a horrible, horrible program, and you are expected to make up the difference by experimentation.

Its so complicated as to make it more worthwhile just to list every file and filter them out with other utilities. Honestly, why go through so much trouble to learn about a command that is as obfuscated as a heartpump?

Sure its great for listing all the files and directories in one subdir, but if you want to exclude multiple dirs or files forget it. Pipe it through grep.

Why Does Grep Return "No Such File Or Directory"?

I copied the following from my linux console.

grep -lr "SMTP" *.ini
grep: *.ini: No such file or directory

I wanted to search recursively under current location in files with extenstion .ini
Actually there are files that contain "SMTP" under this directory. But I got the above error message.
What is wrong? I am using centos 6.

Thanks,
3rock

How To Rename A File In Linux

hello,

I am trying to rename the file by adding .txt extension and also
before renaming, I want to replace . in file with _

right now file looks like this mdm.201504021628

after execution of my script file name should be mdm_201504021628.txt


#!bin/bash
//reading all files from directory

files=$(hadoop fs

-ls /dl/data/landing/hivedb/lnd_attunity_kpi_db_backup/auth_master |
awk '!/^d/ {print $8}')

for f in $files; do

//using sed to replace . with _ and then feeding to hadoop fs command

sed 's/./\_/g' $f | hadoop fs -mv $f $f.txt

done

Thanks for your help in advance.