How to grep for message and if found display filename?
Hi i'm new to the forum and was hoping someone could help me with the following query.
I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage:
e.g:
The code basically runs as a bash script on a linux box with apache and displays it on a browser.
for the failed files it displays the file info. Which basically greps the last 2 lines of the file and if it has failed it displays info from the line:
above log file grep produces:
output on the browser is below:
Now the problem i have is i haven't got enough info to find the log.
Is there a way i can get grep to also get the file name for the failed files.
so maybe a condition:
if the above tail command produced failed results then display the filename?
---------- Post updated at 07:23 AM ---------- Previous update was at 07:20 AM ----------
Quote:
Originally Posted by pravin27
Hi Bartus11,
Could you please explain the xargs code ?
I think instead of using grep two times we can use grep with -w option.
With xargs -i, you can use "{}" where arguments need to be passed. So here it will be substituted with same file name in two places for every file passed from "find" utility.
Script name is test.ksh
I know that that the ssh command is working properly, this can be verified by the value returned in respond variable. It is unique to the remote server
_____________________________________________________
respond=$(ssh $remoteHost find... (3 Replies)
Hi All,
I am working with a XML file.
Below is part for the file.
<Emp:Profile>
<Emp:Description>Admin</Emp:Description>
<Emp:Id>12347</Emp:Id>
</Emp:Profile>
<Emp:Profile>
... (7 Replies)
I am trying to execute a script called tfile.sh in a bash shell in solaris and it throws up the following message
I am getting the required output after this message. How do i get the message to disappear. Can someone please point out my mistake in the script? Thanks in advance
... (13 Replies)
I am executing the following script in a bash shell in solaris and it throws up the following message :
But i get the output that i require nevertheless. Can anyone please spot what is causing the warning and how do i get it go away?
VAR1="e6842w2334f76figtl5.systems.grp"
if 76fig`... (2 Replies)
Hi gurus,
I'm having a strange problem and I hope you can help me solving it.
I'm working in Unix Solaris, version 5.10, ksh.
I have a script with environment variables which I have to execute prior to other scripts. The script belongs to userA and when I log in, and cd to its directory. It... (4 Replies)
Hi,
I am a newbie for shell programming and met some question about redirect output to a file. See the details.
#!/usr/bin/sh
...
./doSomething.pl >> RAW_DATA
echo "testing is done !" >> RAW_DATA
Descirption:
doSomething.pl do a bit complex things and output some message. I append... (3 Replies)
I have shell script as below:
#!/bin/ksh
#set -xv
function set_variable
{
VARIABLE_NAME=$1
CURRENT_PATH=`pwd`
if ; then
echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts"
exit 1;
fi
VARIABLE_COUNT=`cat... (2 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)
Hi there,
I am writing a script to look for tmp log files that have not been access within the last 10 days.
I am using the follwing command within the script:
find /var/tmp -name *log -atime -9 ¦xargs
What I would like to be able to do would be to display a message if there is no... (3 Replies)
I'm just learning UNIX and I'm trying to do the following:
Write a script called details.bash that, for each file in the working directory, prints the filename, the # of lines, and the # of words to to some output file, like this:
filename1 73 431
filename2 5 21
It's probably a stupid... (1 Reply)