grep inside if condition - need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep inside if condition - need help
# 1  
Old 06-16-2010
PHP grep inside if condition - need help

hi i need help with below code.

Code:
if [[ `grep "Error - The script has to be run first" ${LOCAL_DIR}/ar_${DATE}_${ID}.txt` ]]
                        then
log "Exiting the script as ID= NULL"
log "Please run script first."
fi

i am calling grep inside this but its not running any ideas why ??

input file is like this --

Code:
 
Msg 102, Level 20, State 1:
Server 'VA_DS', Line 12:
Incorrect syntax near 'Error - The script has to be run first'.

need help urgently
# 2  
Old 06-16-2010
Quote:
Originally Posted by dazdseg
hi i need help with below code.

Code:
if [[ `grep "Error - The script has to be run first" ${LOCAL_DIR}/ar_${DATE}_${ID}.txt` ]]
                        then
log "Exiting the script as ID= NULL"
log "Please run script first."
fi

i am calling grep inside this but its not running any ideas why ??

input file is like this --

Code:
 
Msg 102, Level 20, State 1:
Server 'VA_DS', Line 12:
Incorrect syntax near 'Error - The script has to be run first'.

need help urgently

Works fine on my end

Code:
cat file.sh
if [[ `grep "Error - The script has to be run first" file.txt` ]]
                        then
echo "Exiting the script as ID= NULL"
echo "Please run script first."
fi
s:/tmp # sh file.s
file.s: file.s: No such file or directory
s:/tmp # sh file.sh
Exiting the script as ID= NULL
Please run script first.

# 3  
Old 06-16-2010
Can't see any error either. Maybe post or describe your error.

Regarding:
Quote:
need help urgently
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
# 4  
Old 06-16-2010
I am extremely sorry for posting something with need urgent help. it will not happen again.

@3junior i dont know why it doesnt work for me

i m getting the below error :-
Code:
./Script.ksh[30]: syntax error at line 274 : `]]' unexpected

and i m using this code:-

Code:
if [[ `grep "Error - The script has to be run first" ${LOCAL_DIR}/bor_${DATE _${ID}.txt` ]]
then
echo "exiting the script as id= null"
echo "please run script 1s"
fi

any ideas i have already. put the error..
# 5  
Old 06-16-2010
Code:
 
 
${LOCAL_DIR}/bor_${DATE_${ID}.txt

There is a space after ${DATE.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying awk code to be inside condition

I have the following awk script and I want to change it to be inside a condition for the file extension. ################################################################################ # abs: Returns the absolute value of a number function abs(val) { return val > 0 ? val \ ... (4 Replies)
Discussion started by: kristinu
4 Replies

2. Shell Programming and Scripting

matching patterns inside a condition in awk

I have the following in an awk script. I want to do them on condition that: fext == "xt" FNR == NR { />/ && idx = ++i $2 || val = $1 next } FNR in idx { v = val] } { !/>/ && srdist = abs($1 - v) } />/ || NF == 2 && srdist < dsrmx {... (1 Reply)
Discussion started by: kristinu
1 Replies

3. Shell Programming and Scripting

Check condition inside the loop

Hi, I am in trouble. I can get inside my condition test inside a loop : I am in ksh (solaris) while read file do <commande to retrieve file> >> ${LOG_RETRIEVE_FILE.log} msg_err=$(cat ${LOG_RETRIEVE_FILE.log} | grep "error retrieve") if ; then <sendmail> exit 1 fi done I tried... (6 Replies)
Discussion started by: Aswex
6 Replies

4. Shell Programming and Scripting

FTP Command inside If condition

Hi All, I am facing a alien problem in unix shell script. i have a requirement where i have to check first whether a particular file has been created or not if that file has been created then that file needs to be ftped to a particular dir. My Code is like that Success='code for file... (3 Replies)
Discussion started by: aryan_styles
3 Replies

5. Shell Programming and Scripting

If condition inside while???

Hi source is text file named alpha.text containing entries ABC DEF XYZ YYY BBB I need a small shell script which should do read the entries in alpha.text one by one and check it with the current date. If the date is Mon (monday) and entry read from the file is 'DEF' then this should... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

6. Shell Programming and Scripting

using flag inside a for loop to check condition

I have a logic like this It initializes the flag variable as "T" at the beginning of the loop everytime Inside each loop it checks for two conditions and updates the flag variable as "A" or "B" In the end of the loop it checks for the value of the variable flag for "A" or "B" and execute... (4 Replies)
Discussion started by: codeman007
4 Replies

7. Shell Programming and Scripting

Extract value inside <text> tag for a particular condition.

Hi All! I have obtained following output from a tool "pdftohtml" :: So, my input is as under: <text top="246" left="160" width="84" height="16" font="3">Business purpose</text> <text top="260" left="506" width="220" height="16" font="3">giving the right information and new insights... (3 Replies)
Discussion started by: parshant_bvcoe
3 Replies

8. Shell Programming and Scripting

condition inside a for loop

I have a for loop in my script as shown below. for file_path in $file_list ; do ........my code .......... ...... done Can i restrict the number of files parsing to the variable file_path as 50? That is, even if I have some 100 files in file_list, I need to take only 50 files for... (7 Replies)
Discussion started by: Vijay06
7 Replies

9. Shell Programming and Scripting

Checking condition inside the loop

Hi all, I have one clarification i am using the loop which will process for each record .suppose there is f ailure in the first record it need to send mail and process the next .my code: defcount=`cat <filename>|wc -l` while ] do if <some condiotion> then echo "mail" fi done so... (1 Reply)
Discussion started by: ithirak17
1 Replies

10. Shell Programming and Scripting

script to check for a condition inside a file

Hi I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd: ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log the temp.log looks like this: 16 190_GSTV_HUX_003QISCGSK026_message070321.log ... (11 Replies)
Discussion started by: kiran1112
11 Replies
Login or Register to Ask a Question