Hi,
I have a question, during my readings it appears that these two variables in the snippet below need to be on the same line to return a “true” answer and listed in the output otherwise it won’t be returned. How can I write this snippet to make it return a “true” if those two variables are on two separate lines in the trace file?? How would this piece of the code be written?
Or am I misunderstanding something here?
Thanks in advance.
Last edited by Corona688; 01-22-2015 at 04:04 PM..
Reason: Code tags, not font tags
First off, your regex is a little strange. "$2015-01-22" is nonsensical because $ means "match the end of the line", and there's nothing after the end of the line. Did you mean ^, "match the beginning of the line"? It will also take your spaces literally, so "(...) | (...)" means "match this block and a space, or match a space then this block".
But anyways, grep can't can't remember what happened in past lines. It's not a programming language.
awk can remember what's happened in past lines, because it is.
If it finds lines matching "2015-01-22.*NS Primary Error" it sets the variable A true. If it finds lines matching "NS Primary Error.*2015-01-22" it sets the variable B true. If, once all lines are read, both A and B are true, it returns 0(i.e. success), otherwise returns 1 (failure) to the shell.
You might list the lines of each pattern in different work files a and b using 2 egrep patterns/passes, and then sort each (comm needs a binary not ascii-numeric sort) and use 'comm' -3 to remove the same-line entries. What comes out is either a file lines or b file lines prefixed with a tab.
Hi Vgers
Have to admit I am really new at this and am trying to learn by reading and doing.
The code that I listed was wrong I was just trying something. I tried your code and it returned a number (29). I went into the file to verify if it returned the right number but it didn’t. I counted 5 2015-01-22 instances of this search string and 24 instances of the NS primary error string. See output below.
What I need to have is to return true only that number that has BOTH the date and the NS primary error string which the answer should be 5.
I am thinking that there should be two egreps on for 2015-01-22 and then egrep for NS primary error.
Here is the data that egrep is looking for together (highlighted) snippet from trace file
Both of these highlighted must return true to be counted.
My updated script from your suggestion does this:
The first half of the script returns the following so when that info gets to the second egrep it will always return zero.
RETURNS THE FOLLOWING OUTPUT:
Right now I am stumped. I hope this additional information helps.
Thanks in advance
al
---------- Post updated at 07:03 PM ---------- Previous update was at 06:43 PM ----------
Hi Corona,
Thanks for taking a look at this for me. I am really new at this and am currently learning on the job.
I ran your statement on the server and it returned the following error:
I ran it with just one trace file with known information in it. In the end though I will need to go through the entire directly of trace files to find the appropriate ones.
Regards,
al
Last edited by Scrutinizer; 01-23-2015 at 01:14 AM..
Reason: Rooted out formatting, introduced code tags
--
Your egrep approach will not work, because it is line based. The syntax of the second part is incorrect too and it the regular expression on the first part can be reduced to
In the first example you use a -c option which counts the number of appearances. But now it is the actual result you are after?
Please provide a corresponding input sample and output sample and also verbally describe what result you are trying to achieve. It also helps if you state your specific operating system and version. I guessed it this time from the error message you reported....
---
Also, to find al matches, try:
Or, to combine this with count and exit status, like Corona688 suggested, try something a bit more elaborate:
Last edited by Scrutinizer; 01-23-2015 at 01:55 AM..
Yes, even 'sed' is more capable of dealing with multiple lines, using 'N' to pile up the entre block for testing, perhaps removing all but interblock line feeds.
Hi
I have a txt file and I would like to use egrep without using -v option to exclude the lines which matches with multiple Strings.
Let's say I have some text in the txt file. The command should not fetch lines if they have strings something like
CAT MAT DAT
The command should fetch me... (4 Replies)
Its really 2 questions, but both are pretty basic.
Linux Redhat
1. Need to do a search and replace on a file.
I need to append '--' (comment out the line) to specific lines based on a wildcard search.
So if I Have
GRANT SOME_ROLE_OR_USER ...
I dont care what comes after that.... (2 Replies)
Hi all
I need your help to get a high-performance solution.
I am working on a extensive script to automate file restores using the bprestore tool on a Solaris 5.10 server (bash 3.00). I will only paste the needed parts of the script to avoid any confusion.
To use the script the user has to... (2 Replies)
test.txt:
appleboy
orangeletter
sweetdeal
catracer
conducivelot
I want to only grep out lines that contain "appleboy" AND "sweetdeal". however, the closest thing to this that i can think of is this:
cat test.txt | egrep "appleboy|sweetdeal"
problem is this only searches for all... (9 Replies)
Hi, i have a a bunch of directories that are always named with six lowercase alpha's and either one or two numeric's (but no more)
so for example names could be
qwerty1
qwerty9
qwerty10
qwerty67
I am currently using two pattern matches to capture these names
echo $DIR |... (8 Replies)
Hello all,
I'm a first time poster and a unix/linux noob so please be understanding.
I am trying this command below:
# egrep -c "Oct".+"Connect: ppp" /var/log/messages*
/var/log/messages:53
/var/log/messages.1:35
/var/log/messages.2:63
/var/log/messages.3:27
/var/log/messages.4:12
... (1 Reply)
I want to egrep for certain fields which are not existing in the current log files and am getting errors for that...
egrep "'^20090220.14'|'^20090220.15'|'^20090220.16'|'^20090220.17'|'^20090220.18'"
Some of the times are in future and logs don't have those entries and I get errors for them... (1 Reply)
I have a script that does the following. It searches a listing of directories with specific extensions and then formats a wc on those files. The code looks like this
find <directory> -name '*.js' -o -name '*.html' | awk '{print \"wc -l \"$1}' > file \n"
The result is a file with the "wc -l"... (7 Replies)
Hi,
Can someone help me count this line:
Say I have a file (file1.txt) that contains below:
11/16 13:08:19.5436 18096 --- Generating a <reading> event
11/16 13:08:19.7784 18096 ---- Sending a <writing> event
11/16 13:08:37.4516 18096 --- Generating a <reading> event
11/16... (1 Reply)
Hi
I am trying to use this command:
egrep '^a{2,6}$' testexpr4D
to retreive lines with 2,3,4,5, or 6 a's in a file .
The file testexpr4D has entries like:
a
aa
aaa
aaaa
aaaaa
aaaaaa
123456
ABCDEF
I was expecting to see 5 lines in the output but nothing happens.
Can anyone help... (10 Replies)