To search for a text in until i find that


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To search for a text in until i find that
# 1  
Old 08-30-2005
Question To search for a text in until i find that

In a CSH, i need to write a loop to seach continuously for text "Started" and then only exit from the loop when ever if finds that.

Can someone please suggest how we can write this
Thanks,
Sateesh
# 2  
Old 08-30-2005
People are going to tell you not to use csh, but that's up to you.

What have you done so far? Please post some sample code so we can see where you're having problems. Also, where is the text "Started" - in a growing log file that's being appended to, in random files scattered over the filesystem, etc, etc????

Cheers
ZB
# 3  
Old 08-30-2005
Hi,

My script is below and i am getting error "if:Expression Syntax" when i run this.
Could someone please help why i am getting this error?

-----
#!/bin/csh
set count = 0
set timecount = 0
while ($count < 1)
set count=`grep "Engine finished startup" /home/ficctprd/KA_SWCCT_PROD_NY_nbswpsa52/log/keepalive.lo
g |wc -l`
echo "Sleeping for 60 Seconds"
#sleep 60
set timecount = `expr $timecount + 1`
if ( $timecount -gt 4 )
then
echo "Not Started Successfully"
break
endif
end
echo $count
echo $timecount
------
# 4  
Old 08-30-2005
Try this

Code:
#! /bin/csh

set count = 0
set timecount = 0

while ($count < 1)
set count=`grep -c "Engine finished startup" /home/ficctprd/KA_SWCCT_PROD_NY_nbswpsa52/log/keepalive.log`
echo "Sleeping for 60 Seconds"
#sleep 60
set timecount = `expr $timecount + 1`
if ($timecount > 4) then
echo "Not Started Successfully"
break
endif
end
echo $count
echo $timecount


I have changed your grep statement as well. The -c will give you the count.

vino
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

3. Shell Programming and Scripting

Search: find current line, then search back

Hello. I want to find a line that has "new = 0" in it, then search back based on field $4 () in the current line, and find the first line that has field $4 and "last fetch" Grep or Awk preferred. Here is what the data looks like: 2013-12-12 12:10:30,117 TRACE last fetch: Thu Dec 12... (7 Replies)
Discussion started by: JimBurns
7 Replies

4. UNIX for Dummies Questions & Answers

find Search - Find files not matching a pattern

Hello all, this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction. My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Discussion started by: kilobyter
7 Replies

5. Linux

Search only text files with 'find' command?

I've been using this to search an entire directory recursively for a specific phrase in my code (html, css, php, javascript, etc.): find dir_name -type f -exec grep -l "phrase" {} \; The problem is that it searches ALL files in the directory 'dir_name', even binary ones such as large JPEG... (2 Replies)
Discussion started by: Collider
2 Replies

6. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

7. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. UNIX for Advanced & Expert Users

find file with date and recursive search for a text

Hey Guyz I have a requirement something like this.. a part of file name, date of modification of that file and a text is entered as input. like Date : 080206 (MMDDYY format.) filename : hotel_rates text : Jim now the file hotel_rates.ZZZ.123 (creation date is Aug 02 2006) should be... (10 Replies)
Discussion started by: rosh0623
10 Replies
Login or Register to Ask a Question