Issue with null value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with null value
# 1  
Old 06-14-2012
Issue with null value

Hi,
I am trying below code. let me explain what is going on here.

Code:
xmitq=`echo "dis qr($queue) xmitq"|runmqsc $QMGR| tr ' ' '\n' | sed 's/^*//g'|grep "XMITQ"| cut -d '(' -f2| cut -d ')' -f1`
 
chl=`echo "dis chl(*) xmitq"| runmqsc $QMGR |egrep 'CHANNEL|XMITQ'|\
egrep -v 'CLUSSDR|CLUSRCVR|RCVR|SYSTEM|SVRCONN'|sed 's/CHANNEL(/+/g'|\
tr -d '\n'|tr '+' '\n'|grep "$xmitq"|sort -u|awk '{print $1}'|\
sed -e 's/(/ /' -e 's/)/ /'`
 
ip=`echo "dis chl("$chl") conname"|runmqsc $QMGR | tr ' ' '\n' | sed 's/*^//'| grep "CONNAME"| cut -d '(' -f2`
echo $xmitq,$chl, $ip

from xmitq we get some details and some times xmitq value can be null also...
based on xmitq we get $chl and from $chl we get $ip values
but here problem is when xmitq value is "null" it is throwing below exception

Code:
grep: RE error 41: No remembered search string.

So i am looking for if xmitq is null (no value) then it should print blank for $chl and $ip.
it is a loop for example if i get
$xmitq as first and firstchl and firstip are $chl, $ip values accordingly
$xmitq is null it should print blank values for $chl and $ip (if possible $ip is blank i would like to get "CONNAME" text in $ip place, it is optional)
$xmitq is eight and eightchl and eightip are $chl, $ip values accordingly
this loop continues untill we get xmitq values
# 2  
Old 06-14-2012
Please post what Operating System and version you are using.
Please post what Shell this is.

The solution is in the question:
"So i am looking for if xmitq is null (no value) then it should print blank for $chl and $ip."
Code:
if [ "${xmitq}""X" = "X" ]
then
       # set the other values to blank
else
       # derive the values
fi

There are tidier ways of determining if a variable is empty but this depends on the Shell you are running at the time.

Ideally post some sample input data and expected output data. We are not psychic.

Ps. I don't understand the bit about "eight" whatsoever or much or the other ramblings. A well-prepared example would help.
Has this post been through a translator from a foreign language?

Last edited by methyl; 06-14-2012 at 07:57 PM..
# 3  
Old 06-15-2012
It should work on SUNOS, Linux,HP- UX.. shell is ksh

---------- Post updated at 04:55 AM ---------- Previous update was at 04:02 AM ----------

command to grep exact value.. problem is if xmitq output is X and if anyother xmitq output also having x say "BX" it is taking that also
is there any command to grep exact xmitq value
i treid grep -w $xmitq but not working
# 4  
Old 06-15-2012
Try using awk and shell in this formulation when working with IBM MQ cli.

For instance, for XMITQ variable :

Code:
QUEUE=YOURQUEUE
QMGR=YOURQUEUEMANAGER
XMITQ=$(
(
runmqsc -e $QMGR <<EOF
dis qr($QUEUE) xmitq
EOF
) | awk '/XMITQ/{ print (match($0,/\([^ ].*\)/)) ? substr($0,RSTART+1,RLENGTH-2) : "NULL" } '
)
echo $XMITQ

This will return NULL string (or if you wish something else) if the XMITQ is non existant or set value to XMITQ if the output contains it.

Hope that helps.
Regards
Peasant.
# 5  
Old 06-18-2012
It is fixed now...

I have few more issues..

in "case"
Code:
SunOS) Echo "OS is SUN"
             version = `dspmqver'
               case $version in
                6) echo "sunos and not 5";;
                7) echo " sunos and not 5";;
esac;;
esac

for version 6 and 7 i need to write same output. in this case instead of writing two times or more than that.. is there any simple way to execute same thing for both 6 and 7?
# 6  
Old 06-19-2012
Use or
Code:
case $VAR in
6|7) It's $VAR
;;
esac

Please open new threads for new problems.

Regards
Peasant.
# 7  
Old 06-19-2012
There are syntax errors in the script snippet you post.
Remove space character either side of equals line.
Lose the extra ;; on the esac line.
Indent sensibly to make it easier to read

In this example the value 5 causes the script to execute the ":" command (i.e. do nothing) and any other value displays the message.
Code:
             version=`dspmqver'
             case $version in
                   5) : ;;
                   *) echo "sunos and not 5";;
             esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Issue in inserting null string in array

I am getting some values from a file and putting them in an array..but the null strings are not getting passed to the array. So during printing the elements ,the null string is not showing in the output. during array size calculation it is also excluding null.Please let me know how to do it. # cat... (2 Replies)
Discussion started by: millan
2 Replies

2. AIX

/dev/null file issue

Hi Experts, I Have a query. In one of my server I just came to know that there was /dev/null file which is a not a character file. Its just a normal file. I know the command to create the character file (/dev/null) but what is the procedure. Like should i delete /dev/null and create or... (7 Replies)
Discussion started by: jayadeava
7 Replies

3. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

4. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

5. Shell Programming and Scripting

Insert string 'NULL' where there is a null value

I have an input file having 7 fields delimited by , eg : 1,ABC,hg,1,2,34,3 2,hj,YU,2,3,4, 3,JU,kl,4,5,7, 4,JK,KJ,3,56,4,5 The seventh field here in some lines is empty, whereas the other lines there is a value. How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Discussion started by: zilch
8 Replies

6. Shell Programming and Scripting

compare null with non-null

I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Discussion started by: nitin
8 Replies

7. IP Networking

Could a tcp issue be causing a null pointer exception?

The client's app gets a 'suspend error' which they say is due to a null pointer exception. Application people say nothing's wrong with the app. Network people say the network's fine. I'm supposed to see what's wrong with the system to be causing this error. I checked the NIC card settings, which... (1 Reply)
Discussion started by: pmichner
1 Replies

8. Shell Programming and Scripting

Varibale to NULL or ZERO

I have a variable called V_param1 and does it have some value. I want to check this varibale is NULL or Zero then exit else do How to incorported this in Script. any input (2 Replies)
Discussion started by: u263066
2 Replies

9. UNIX for Advanced & Expert Users

Null Value

Hello All, I have a file of the format **** 123 abc ABC 456 bcd BCD 789 def 112 ghi GHI 223 jkl 344 mno MNO **** I am trying to extract the lines that have no values in the third field (in this case, this would be 789 def 223 jkl Can anyone please help??... (1 Reply)
Discussion started by: Khoomfire
1 Replies

10. UNIX for Advanced & Expert Users

Has anyone seen this issue with the /dev/null?

hello all, I am working in a Hpux 11.0 64 bit environment. I am not sure if a third party software is doing this or not, but the admin to this server says it is not a server issue as he has check and double check logs and crons to verify this issue. My problem, is that every now and then, once... (4 Replies)
Discussion started by: oott
4 Replies
Login or Register to Ask a Question