Home > Grep Command > Cat Grep Error

Cat Grep Error

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us have a peek at this web-site Learn more about Stack Overflow the company Business Learn more about hiring grep command in linux with examples developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question grep command linux _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; linux grep regex it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to grep top most frequent error messages in a unix grep output to file logfile up vote 5 down vote favorite 1 If I have a file example apache log file How to extract the top most frequent error messages in a unix log file with no timestamps the key is most frequent error message should come on top of the list linux shell grep webserver share|improve this question edited May 22 '14 at 19:18 Vldb.User 71 asked Oct 23 '13 at 5:22 Jaya William 86224 migrated from serverfault.com Oct 23 '13 at 22:04 This

Grep Filename

question came from our site for system and network administrators. 1 grep message logfile | sort | uniq -c | sort -n | head –MadHatter Oct 23 '13 at 5:45 Sorry, head should read tail. –MadHatter Oct 23 '13 at 5:58 Thanks for the edit, more clearly defining the question; Ursadon has answered it for you, so could you please accept his or her answer so we can stop this question popping up again? As you will gather by the slowly-accumulating downvotes, this question is arguably off-topic for SF. –MadHatter Oct 23 '13 at 7:27 add a comment| 2 Answers 2 active oldest votes up vote 10 down vote cat /tmp/file: ERROR 1 1234 ERROR 2 1234 ERROR 3 1234 ERROR 4 1234 ERROR 4 1234 ERROR 3 1234 ERROR 2 1234 ERROR 5 1234 ERROR 1 1234 ERROR 4 1234 ERROR 1 1234 ERROR 1 1234 ERROR 1 1234 ERROR 3 1234 ERROR 2 1234 ERROR 1 1234 ERROR 4 1234 ERROR 1 1234 ERROR 4 1234 ERROR 1 1234 ERROR 2 1234 grep "ERROR" /tmp/file | sort | uniq -c | sort -r: 8 ERROR 1 1234 5 ERROR 4 1234 4 ERROR 2 1234 3 ERROR 3 1234 1 ERROR 5 1234 first column shows how many occurrences of each string were found Explanation: grep "ERROR" /tmp/file\ # select only ERROR string | sort\ # order | uniq -c\ # count duplicate item

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site Source About Us Learn more about Stack Overflow the company Business Learn

Grep Directory

more about hiring developers or posting ads with us Unix & Linux Questions Tags Users grep current directory Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like ls grep operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Why cat, grep and other http://unix.stackexchange.com/questions/97341/how-to-grep-top-most-frequent-error-messages-in-a-unix-logfile commands can't understand files starting with minus sign? [duplicate] up vote 4 down vote favorite This question already has an answer here: How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)? 8 answers If I have a file which name starting with single or several minus sign, for example --1 it can't be used as a parameter of many commands. Even if I run cat --1 instead of file content I http://unix.stackexchange.com/questions/87355/why-cat-grep-and-other-commands-cant-understand-files-starting-with-minus-sign get unrecognised option error message: cat: unrecognized option '--1' Same effect appears when I type cat "--1" cat '--1' cat \-\-1 nothing works. Files starting with '-' is not illegal in file system, but it is quite hard to work with them in cli and scripts. OK, in case of cat or grep I can use cat <--1 and this will work, but rm --1 won't work either and it is quite hard to substitute this command with something else. Very uncomfortable after all. Is there any universal workaround different from not using such file names? BTW, if name file is single - and all most of commands will understand it as stdin, wouldn't they? And it would be hard not to use such file names since I can't rename them all in script using mv command either. bash shell command-line shell-script share|improve this question asked Aug 19 '13 at 16:36 Nick 14914 marked as duplicate by Evan Teitelman, manatwork, slm♦, Anthon, jasonwryan Aug 19 '13 at 19:45 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. THe short answer would be cat ./--1 or cat -- --1. The long answer has to come yet –val0x00ff Aug 19 '13 at 16:40 mystified at the down-vote on the question –iruvar Aug 19

when using it, whether interactively or in a script. This file attempts to describe some of them, demonstrate that they are indeed mistakes, and show how to avoid them. 0.1 Assumptions Basic familiarity with UNIX http://www.greenend.org.uk/rjk/tech/shellmistakes.html and Bourne shell is assumed: the reader will probably have written simple shell scripts already, and if not will at least know what the idea of a script is. This isn't a complete shell tutorial. 0.2 Typographical Conventions Examples are displayed boxed: Example In transcripts of shell sessions, user input is displayed specially, to distinguish it from the output of the computer: sfere$ echo wibble wibble This will only work if your browser supports grep command style sheets. The distinction between user input and computer output will usually be reasonably obvious from context, however. 1. Redundant cat It seems to be extremely common to use "cat" to feed input into some filter. For example: cat file | grep searchstring The effect of this is to create a pipe, executing "cat file" with its output redirected to the pipe and "grep searchstring" with its input redirected from the pipe. But you can Cat Grep Error eliminate the entire invocation of "cat" by just redirecting grep's input to come from the file: grep searchstring < file Not only does this avoid the time-wasting invocation of "cat", but (depending on the program you are running) it can sometimes make the process more efficient still by giving the program more direct access to the file. (If performance is really vital than you should test the various possibilities rather than speculating that one is faster than another, though.) If what you want is to have the input file at the start rather than the end, you can do that too: < file grep searchstring In this case you can also just pass the name of the file to grep: grep searchstring file In other cases that might change the behaviour, though. 1.1 Exceptions Very occasionally it does make sense to put in the "cat": if the process that reads the input behaves differently depending on whether it is a regular file, a pipe, a terminal, etc, then it might be that turning it into a pipe via the "cat" command makes sense. If you think that use of cat like this boils down to a question of style, read the section error handling, with particular reference to the remarks regarding pipelines. 2. Redundant ls A similar case is the redundant invocatio