Sponsored Content
Top Forums Shell Programming and Scripting shell script - unexpected result Post 302549055 by rajashekar.y on Sunday 21st of August 2011 03:50:44 AM
Old 08-21-2011
shell script - unexpected result

I hv a file --am executing a script which is giving me unexpected results


COntents of file:

f1
Code:
CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX:
CMT_AP1:/opt/sybase/syboc125:150:ASE12_5::Y:UX

f1.tmp
Code:
CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX:
CAT_AP1:/opt/sybase/syboc125:150:ASE12_5::Y:UX

Difference is at 2nd line "CMT" and "CAT"

Script#1
Code:
for i in `grep AP1 f1 |awk -F: '{print $1}'`
do
  DSQUERY=$i
  A15F=`grep AP1  f1| grep ${DSQUERY} | awk -F: '{print $3}'`
  echo "$A15F ----- $i"
  if [ "$A15F" = "150" ]; then
    echo $i
  else
   echo "Version 12.5",$i
  fi
done

ouput:
Code:
150 ----- CMT_AP1_CONT
CMT_AP1_CONT
150
150 ----- CMT_AP1
Version 12.5,CMT_AP1

Script#2:
Code:
for i in `grep AP1 f1 |awk -F: '{print $1}'`
do
  DSQUERY=$i
  A15F=`grep AP1  f1| grep ${DSQUERY} | awk -F: '{print $3}'`
  echo "$A15F ----- $i"
  if [ "$A15F" = "150" ]; then
    echo $i
  else
    echo "Version 12.5",$i
  fi
done

Output 2:
Code:
150 ----- CMT_AP1_CONT
CMT_AP1_CONT
150 ----- CAT_AP1
CAT_AP1

++++++expected behaviour is 2 why script #1 is not working in a desired way..Pls hlelp me..Thanks

Last edited by Scott; 08-21-2011 at 06:03 AM.. Reason: Please use code tags...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Could any one tell me how to do get result in fraction in shell script

Could any one tell me how to do get result in fraction in shell script. I am using expr for division of 2 number but it is giving Quitent. I need it in full fraction value. please helpp. how to do it using "dc" or "bc" (5 Replies)
Discussion started by: Neerajjaiswal
5 Replies

2. Shell Programming and Scripting

unexpected pipeline result with find -exec

Hi All, I probably miss something fundamental here. I want to rename a bunch of files in subdirectories (that might contain white spaces) with names that are related. I thought following could do the job: find . -name *.sh -exec mv {} $(echo {} | sed -e 's/0/1/g') \; Now to be able to... (5 Replies)
Discussion started by: blued
5 Replies

3. Shell Programming and Scripting

Unexpected sed result.

I am in the process of writing a script to change the grub password in the grub.conf file. I thought I had it figured out, but am running into an a problem I can't put my finger on. Command I am running when I find that the grub.conf file contains "password --md5". sed... (1 Reply)
Discussion started by: viRaven
1 Replies

4. Shell Programming and Scripting

get result from database into shell script

hi, I have a script that will logon to a database siebel and do the select query and then get the result in command prompt of unix.Below the script. #!/bin/ksh . $HOME/conf/systemProperties/EnvSetup.properties #set -x while read i do echo $i connect1=`sqlplus -silent... (1 Reply)
Discussion started by: ali560045
1 Replies

5. Shell Programming and Scripting

shell script result to file

Since I'm not an expert in shell scripting, I have question on sending script result to file. I have script like this... if condition=0: then echo "service is not running" | mail -s "Server Status" uname@companyname fi sleep 10 if configtion=1: then echo "service is not running" | mail -s... (3 Replies)
Discussion started by: s_linux
3 Replies

6. Homework & Coursework Questions

A function in shell script,how can i get the right result

there is a directory /data/users/osa/psidp/dmp/files/cimdir ,it have some subdirectories ,and also the subdirectoriy have it's subdirectoriis. I want to get all the leaf nodes of the directory path . but the result of the script is wrong ,how can i get the right result somebody who can help... (1 Reply)
Discussion started by: fw0037
1 Replies

7. Shell Programming and Scripting

Capture unexpected exit in shell script

Hi, I have shell script that checks processes forever. But somehow it is killed and I want to know what causes it. while do check the processes if they are running, if not restart them done I want to capture the output when the script is terminated, how can I do that? /Andreas (2 Replies)
Discussion started by: mr_andrew
2 Replies

8. Shell Programming and Scripting

`(' unexpected error when running a shell script in AIX

Hi, We are moving from linux to AIX servers, and as a result testing our scripts on the new platform. When I run one of our scripts, I get the following error message: ./branchDataUpdate.sh: syntax error at line 21 : `(' unexpected Following is an extract from the script: ...... ........ (1 Reply)
Discussion started by: dawgfather80
1 Replies

9. UNIX for Dummies Questions & Answers

Weird: unexpected result after piping a sort

Hello, And when you think you know the basics of something, UNIX in this case, something like what I will describe below comes along.... On a Linux system, a "typical" directory with some files. Say 20. I do: > ls | sort > mylisting Now when I: > vi mylisting There is mylisting... (13 Replies)
Discussion started by: stavros
13 Replies

10. UNIX for Beginners Questions & Answers

Unexpected result from awk

Hello, Giving those commands: cat > myfile 1 2 3 ^D cat myfile | awk '{ s=s+$1 ; print s}' The output is: 1 3 6 It seems like this command iterates each time on a different row so $1 is the first field of each row.. But what caused it to refer to each row ?. What I mean... (3 Replies)
Discussion started by: uniran
3 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 02:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy