The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 08:00 AM
To CASE or not to CASE, this is my question! olimiles Shell Programming and Scripting 1 08-19-2006 04:54 AM
Ignore case sensitive in Case Switch annelisa Shell Programming and Scripting 1 07-13-2006 04:36 AM
Limitations of awk? Good idea? Bad idea? yongho Shell Programming and Scripting 2 06-08-2005 05:18 PM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 12:07 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-05-2007
Skyybugg's Avatar
Skyybugg Skyybugg is offline
Registered User
  
 

Join Date: Mar 2007
Location: Tampa, FL
Posts: 26
using case to do this might be a bad idea?

Reading this file. I want to read all 4 fields.

If 2 is populated with a p, I want to set $TYPEP to "Printers",
if not should be empty.
If 3 is populated with an r, I want to set $TYPER to "REQ Printers"
if not should be empty.
If 4 is populated with letter o, I want to set $TYPEO to "Orders"
if not should be empty.

The problem I am having is that it looks like case only lets me fall through it once. I canot get $TYPEP $TYPER $TYPEO to reset to empty after reading each record.

Here is snippet of my file, code and output.
======
Here is snippet of my file:
=======
100:::o:
51:p:r::
52:p:r::
53:p:r::

note: my preview of snippet of the file is showing smiles. Maybe we can start a new thing, smile separated values? :cool: (Just kidding!) Not sure how to get rid of that but it is just 4 colon separated fields, 4 records
I replace colons with commas so you can read it correctly:

100,,,o,
51,p,r,,
52,p,r,,
53,p,r,,
=======
code
=======
############
doIt ()
{
echo "Starting Time:" $RTIME
echo "Cycling Servers In Domain: " ${DOMAIN}
echo ${CYCLER}
echo "Reading server List .. for domain " ${DOMAIN}
echo " Reason"
echo " P=Printers"
echo " R=Requisition Printers"
echo "Server O=Orders"
echo "ID Description P R O Node Domain"

typeset -L36 NM_SERVER
typeset -L9 TYPEP
typeset -L16 TYPER
typeset -L10 TYPEO

while read no pflag rflag oflag
do

NM_SERVER=`$GET_NM -getp \\\node\\\\$NODE_NAME\\\domain\\\\$DOMAIN\\\servers\\\\$no\\\ ServerName`

case ${pflag} in p)
TYPEP="Printers"
;;
esac
case ${rflag} in r)
TYPER="REQ Printers"
;;
esac
case ${oflag} in o)
TYPEO="Orders"
;;
esac

typeset -L4 no
typeset -L10 NODE_NAME
typeset -L6 DOMAIN
typeset -L2 pflag
typeset -L2 rflag
typeset -L2 oflag
printf ${no}${NM_SERVER}${TYPEP}${TYPER}${TYPEO}${pflag}${rflag}${oflag}${NODE_NAME}$DOMAIN
#${CYCLER} ${no} ${NODE_NAME} "-l" ${UN} ${DOMAIN} ${PW}
printf "\n"
unset no
typeset -L2 oflag
typeset -L8 NODE_NAME
typeset -L5 DOMAIN

done< ${FILE_PATH}/.${NODE_NAME}.${DOMAIN}.server.lst | tee -a $LOG
}
########
#MAIN
#######
doIt

======
Output
======
ID Description P R O Node Domain
100 ORM Format Server Orders o cerntst1 build
51 CPM Script Orders p r cerntst1 build
52 CPM Code Cache Manager Orders p r cerntst1 build
53 CPM Script Private Orders p r cerntst1 build
====
My Comments
=====
using ksh on AIX 5.3 ML04
You see thar "Orders" prints for each of the 4 lines. It should have only printed for the first. The other 3 should have printed both "Printers" and REQ Printers"
Any suggestion is appreciated. I think I am using the wrong tool. If you can point me to a more suitable function or command or tool, I appreciate it.
SkyyBugg
=====

Last edited by reborg; 04-05-2007 at 04:29 PM..
  #2 (permalink)  
Old 04-05-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Code:
case ${pflag} in 
p)
       TYPEP="Printers"
       ;;
*)
       TYPEP=""
       ;;
esac
case ${rflag} in 
r)
       TYPER="REQ Printers"
       ;;
*)
       TYPER=""
       ;;
esac
case ${oflag} in 
o)
       TYPEO="Orders"
       ;;
*)
       TYPEO=""
       ;;
esac
  #3 (permalink)  
Old 04-05-2007
mukundranjan mukundranjan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 20
Quote:
======
Here is snippet of my file:
=======
100:::O:
51:P:r::
52:P:r::
53:P:r::

If 2 is populated with a p, I want to set $TYPEP to "Printers",
if not should be empty.
If 3 is populated with an r, I want to set $TYPER to "REQ Printers"
if not should be empty.
If 4 is populated with letter o, I want to set $TYPEO to "Orders"
if not should be empty.
See your file is and logic is clear, but what output you want from this is not clear, can you write down you output only..
  #4 (permalink)  
Old 04-06-2007
Skyybugg's Avatar
Skyybugg Skyybugg is offline
Registered User
  
 

Join Date: Mar 2007
Location: Tampa, FL
Posts: 26
Quote:
Originally Posted by Perderabo
Code:
case ${pflag} in 
p)
       TYPEP="Printers"
       ;;
*)
       TYPEP=""
       ;;
esac
case ${rflag} in 
r)
       TYPER="REQ Printers"
       ;;
*)
       TYPER=""
       ;;
esac
case ${oflag} in 
o)
       TYPEO="Orders"
       ;;
*)
       TYPEO=""
       ;;
esac
I replaced my case section with this one and now TYPEO is populated on first row but not the rest. TYPEP and TYPER showing empty on all rows!
Not sure why. Maybe I should post entire script, but I put *alot* of documentation in there. I have high hopes for the script and doc and script are not complete and out of synch! Sometimes (alot of times!)results are what you least expect!
  #5 (permalink)  
Old 04-06-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
To debug it try:
Code:
echo oflag = $oflag
case ${oflag} in 
o)
       TYPEO="Orders"
       ;;
*)
       TYPEO=""
       ;;
esac
echo TYPEO = $TYPEO
You will find that oflag was not set to "o" if TYPEO is getting set to "".
  #6 (permalink)  
Old 04-06-2007
Skyybugg's Avatar
Skyybugg Skyybugg is offline
Registered User
  
 

Join Date: Mar 2007
Location: Tampa, FL
Posts: 26
That is the kind of behaviour of case is is perplexing me. I don't want to be assuming but I am attaching input, output and the entrire script. You will see in the input file towards the middle and end, oflag is set to o and the TYPO is still not populating. I wonder if TYPO isn't a reserved variable?
SkyyBugg
Attached Files
File Type: txt POWER_CYCLE.txt (3.2 KB, 11 views)
  #7 (permalink)  
Old 04-06-2007
Skyybugg's Avatar
Skyybugg Skyybugg is offline
Registered User
  
 

Join Date: Mar 2007
Location: Tampa, FL
Posts: 26
I missed the errors on the upload of other two files. Here they are.
ok That was output, this is the script. I had to take the "." off of the fileneme of my input file, windoze made me do it.
Attached Files
File Type: txt power_cycler.ksh.txt (1.6 KB, 11 views)
File Type: txt cerntst1.build.server.lst.txt (214 Bytes, 9 views)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0