Lets say I have a file containing string patterns to be looked for inside a file.
I would normaly do :
grep -if MyFilePattern FiletoSearchInto
if I use the -c it gives how many total lines it found out of my whole pattern file, but what if i want grep to report how many times it found each records in the MyFilePattern file ?
This is to help me at my job to make sure whenever I do this, that I would either find each lines once or none at all. If one line is there more then once, then I have a problem that I must fix.
The -q option of grep means "quiet": with this option grep gives a returncode 0 if it found the pattern and 1 of not. Additionally one doesn't have to get rid of the output as there is none. To use grep -q in a compound command use
Here is a little script, which accepts a filename and a pattern (in principle any regexp should work, but i haven't tested it with more complicated ones - there may arise problems with the shell interpreting it in this case) and prints out the number of occurrences:
The script makes use of a certain feature of sed: to change only the first ocurrence of the pattern in a substitute-operation, as long as the g-clause is not given. The command
will only change the first occurrence of "pattern", to change all one would have to write:
The inner loop "chops off" one occurrence of pattern after the other, until none is left. For every chop-off-operation a counter is increased.
I am new to grep and Linux and am looking to see if grep can parse out a list of lines that have a difference of more than 10 seconds between the times on each line.
Example
2016-09-17 19:30:57 INFO: id: 4562079216, time: 2016-09-17 19:30:41,
2016-09-17 12:02:26 INFO: id:... (26 Replies)
URGENT HELP IS NEEDED!!
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
- Also the matching lines are not moving out of File1.txt
... (1 Reply)
Hi,
here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found
line1
Line2
Line3
Error
Line4
Line5
Line6
Line7
I want the output to be
Line2
Line3
Error
Line5 (1 Reply)
Hi all,
The task I have sounds easy enough but my solution seems too much complicated and I would like some ideas/feedback on how to achieve the same goal with a more elegant solution on HP-UX B.11.23 (a grep with a regexp would be nice, I did not manage to do a working one :/ )
Here is my... (4 Replies)
Want to write a function that prints an error when passed a list of file names. If the file list is empty, print error "no file found", if there are more than one file, print "error more than one file found" (22 Replies)
hey guys,
I tried searching but most 'search and replace' questions are related to one liners.
Say I have a file to be replaced that has the following:
$ cat testing.txt
TESTING
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
ENDTESTING
This is the input file: (3 Replies)
All:
OS version HP-UX ga016a501 B.11.31 U ia64
from the command prompt -grep for 1 to 11 occurences of "," returns both rows
from the command prompt -grep for 11 occurences of "," returns 0 rows - should be 1 row.
Any ideas - why?
ga016a501 -> grep ',\{1,11\}' test3 | more ... (7 Replies)
Hello Everyone,
i need to read specific number of lines ( always serialized ; i.e from 10 to 20 or from 34 to 44 ) in a file , where the first line is found by grep 'ing a keyword.
example
file.txt
------------------------------------------------------------------
--header
this is the... (7 Replies)
Hello,
How do I use grep to find a pattern in a list of file and then display 5 lines after the pattern is matched
Eg:
I want to match the string GetPresentCode in all files in a folder and then see 4 lines following this match. I am not sure if grep is what should be used to achieve. Thanks!... (3 Replies)