Sponsored Content
Full Discussion: Optimize the nested IF
Top Forums Shell Programming and Scripting Optimize the nested IF Post 302591971 by machomaddy on Sunday 22nd of January 2012 05:12:37 AM
Old 01-22-2012
Optimize the nested IF

Hi,
I have to assign a value for a varaiable based on a Input. I have written the below code:
Code:
if [ "$procnam" == "admission" ]
 then
  nf=65
elif [ "$procnam" == "reporting" ]
 then
  nf=46
elif [ "$procnam" == "transfer" ]
 then
  nf=164
elif [ "$procnam" == "diagnosis" ]
 then
  nf=545
elif [ "$procnam" == "emergeny" ]
 then
  nf=56
elif [ "$procnam" == "inpatient" ]
 then
  nf=37
else
exit 0
fi

Can someone give me an idea of how to optimize it/make this short?
Also, what should be done to do a incase-sensivite comparison?

Like,
Code:
if [ "$procnam" == "Admission" ]
 then
  nf=65
elif [ "$procnam" == "REPORTING" ]
 then
  nf=46
...
fi

Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

optimize the script

Hi, I have this following script below. Its searching a log file for 2 string and if found then write the strings to success.txt and If not found write strings to failed.txt . if one found and not other...then write found to success.txt and not found to failed.txt. I want to optimize this... (3 Replies)
Discussion started by: amitrajvarma
3 Replies

2. UNIX for Dummies Questions & Answers

Can we optimize this simple script ?

Hi All , I am just a new bie in Unix/Linux . With help of tips from 'here and there' , I just created a simple script to 1. declare one array and some global variables 2. read the schema names from user (user input) and want2proceed flag 3. if user want to proceed , keep reading user... (8 Replies)
Discussion started by: rajavu
8 Replies

3. AIX

How to optimize our tape backups ?

Hi, I am currently looking at how we can optimize and speed up our backups here. I am just a beginner operator and our system admin hardly knows anything (long term interim). There is this particular TAR backup of DB backups that for a 10.5Gb amount of files, it takes 5 hours to do the backup on... (6 Replies)
Discussion started by: Browser_ice
6 Replies

4. Shell Programming and Scripting

optimize for file reading

HI, I am new to unix . I don't know it is proper place to put my doubt or not .In my requirement , I am reading a file data and validating each fields and one record having 11 fields and each field having specific length.so when i read the file and validation the 11 fields. It taking 3-4 min per... (2 Replies)
Discussion started by: julirani
2 Replies

5. Shell Programming and Scripting

can we optimize this command

can we optimize this command ? sed 's#AAAA##g' /study/i.txt | sed '1,2d' | tr -d '\n\' > /study/i1.txt; as here i am using two files ...its overhead..can we optimise to use only 1 file sed 's#AAAA##g' /study/i.txt | sed '1,2d' | tr -d '\n\' > /study/i.txt; keeping them same but it... (9 Replies)
Discussion started by: crackthehit007
9 Replies

6. Shell Programming and Scripting

pl help me to Optimize the given code

Pl help to me to write the below code in a simple way ... i suupose to use this code 3 to 4 places in my makefile(gnu) .. **************************************** @for i in $(LIST_A); do \ for j in $(LIST_B); do\ if ;then\ echo "Need to sign"\ echo "List A = $$i , List B =$$j"\ ... (2 Replies)
Discussion started by: pk_arun
2 Replies

7. Shell Programming and Scripting

Optimize awk command

WARNING=${1} CRITICAL=${2} echo ${OUTPUT} | gawk -F'' ' { V = $2 R = $0 } END { for ( i = 1; i <= n; i++) { if((V > 0) && (V < V)) print R, ((V - V) / V) * 100 else if ((V > V) && (V > 0)) ... (6 Replies)
Discussion started by: SkySmart
6 Replies

8. Shell Programming and Scripting

Optimize my mv script

Hello, I'm wondering if there is a quicker way of doing this. Here is my mv script. d=/conversion/program/out cd $d ls $d > /home/tempuser/$$tmp while read line ; do a=`echo $line|cut -c1-5|sed "s/_//g"` b=`echo $line|cut -c16-21` if ;then mkdir... (13 Replies)
Discussion started by: whegra
13 Replies

9. Shell Programming and Scripting

Looking to optimize code

Hi guys, I feel a bit comfortable now doing bash scripting but I am worried that the way I do it is not optimized and I can do much better as to how I code. e.g. I have a whole line in a file from which I want to extract some values. Right now what I am doing is : STATE=`cat... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

10. Shell Programming and Scripting

Help Optimize the Script Further

Hi All, I have written a new script to check for DB space and size of dump log file before it can be imported into a Oracle DB. I'm relatively new to shell scripting. Please help me optimize this script further. (0 Replies)
Discussion started by: narayanv
0 Replies
UNIFDEF(1)							Programmer's Manual							UNIFDEF(1)

NAME
unifdef, unifdefall -- remove preprocessor conditionals from code SYNOPSIS
unifdef [-bBcdehKkmnsStV] [-Ipath] [-[i]Dsym[=val]] [-[i]Usym] ... [-x {012}] [-M backext] [-o outfile] [infile ...] unifdefall [-Ipath] ... file DESCRIPTION
The unifdef utility selectively processes conditional cpp(1) directives. It removes from a file both the directives and any additional text that they specify should be removed, while otherwise leaving the file alone. The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines. A directive is only processed if the symbols specified on the command line are sufficient to allow unifdef to get a definite value for its control expression. If the result is false, the directive and the following lines under its control are removed. If the result is true, only the directive is removed. An #ifdef or #ifndef directive is passed through unchanged if its controlling symbol is not specified on the command line. Any #if or #elif control expression that has an unknown value or that unifdef cannot parse is passed through unchanged. By default, unifdef ignores #if and #elif lines with constant expressions; it can be told to process them by specifying the -k flag on the command line. It understands a commonly-used subset of the expression syntax for #if and #elif lines: integer constants, integer values of symbols defined on the command line, the defined() operator, the operators !, <, >, <=, >=, ==, !=, &&, ||, and parenthesized expressions. A kind of ``short circuit'' evaluation is used for the && operator: if either operand is definitely false then the result is false, even if the value of the other operand is unknown. Similarly, if either operand of || is definitely true then the result is true. In most cases, the unifdef utility does not distinguish between object-like macros (without arguments) and function-like arguments (with arguments). If a macro is not explicitly defined, or is defined with the -D flag on the command-line, its arguments are ignored. If a macro is explicitly undefined on the command line with the -U flag, it may not have any arguments since this leads to a syntax error. The unifdef utility understands just enough about C to know when one of the directives is inactive because it is inside a comment, or affected by a backslash-continued line. It spots unusually-formatted preprocessor directives and knows when the layout is too odd for it to handle. A script called unifdefall can be used to remove all conditional cpp(1) directives from a file. It uses unifdef -s and cpp -dM to get lists of all the controlling symbols and their definitions (or lack thereof), then invokes unifdef with appropriate arguments to process the file. OPTIONS
-Dsym=val Specify that a symbol is defined to a given value which is used when evaluating #if and #elif control expressions. -Dsym Specify that a symbol is defined to the value 1. -Usym Specify that a symbol is undefined. If the same symbol appears in more than one argument, the last occurrence dominates. -iDsym[=val] -iUsym C strings, comments, and line continuations are ignored within #ifdef and #ifndef blocks controlled by symbols specified with these options. -b Replace removed lines with blank lines instead of deleting them. Mutually exclusive with the -B option. -B Compress blank lines around a deleted section. Mutually exclusive with the -b option. -c Complement, i.e., lines that would have been removed or blanked are retained and vice versa. -d Turn on printing of debugging messages. -e By default, unifdef will report an error if it needs to remove a preprocessor directive that spans more than one line, for example, if it has a multi-line comment hanging off its right hand end. The -e flag makes it ignore the line instead. -h Print help. -Ipath Specifies to unifdefall an additional place to look for #include files. This option is ignored by unifdef for compatibility with cpp(1) and to simplify the implementation of unifdefall. -K Always treat the result of && and || operators as unknown if either operand is unknown, instead of short-circuiting when unknown op- erands can't affect the result. This option is for compatibility with older versions of unifdef. -k Process #if and #elif lines with constant expressions. By default, sections controlled by such lines are passed through unchanged because they typically start ``#if 0'' and are used as a kind of comment to sketch out future or past development. It would be rude to strip them out, just as it would be for normal comments. -m Modify one or more input files in place. -M backext Modify input files in place, and keep backups of the original files by appending the backext to the input filenames. -n Add #line directives to the output following any deleted lines, so that errors produced when compiling the output file correspond to line numbers in the input file. -o outfile Write output to the file outfile instead of the standard output when processing a single file. -s Instead of processing an input file as usual, this option causes unifdef to produce a list of symbols that appear in expressions that unifdef understands. It is useful in conjunction with the -dM option of cpp(1) for creating unifdef command lines. -S Like the -s option, but the nesting depth of each symbol is also printed. This is useful for working out the number of possible com- binations of interdependent defined/undefined symbols. -t Disables parsing for C strings, comments, and line continuations, which is useful for plain text. This is a blanket version of the -iD and -iU flags. -V Print version details. -x {012} Set exit status mode to zero, one, or two. See the EXIT STATUS section below for details. The unifdef utility takes its input from stdin if there are no file arguments. You must use the -m or -M options if there are multiple input files. You can specify inut from stdin or output to stdout with '-'. The unifdef utility works nicely with the -Dsym option of diff(1). EXIT STATUS
In normal usage the unifdef utility's exit status depends on the mode set using the -x option. If the exit mode is zero (the default) then unifdef exits with status 0 if the output is an exact copy of the input, or with status 1 if the output differs. If the exit mode is one, unifdef exits with status 1 if the output is unmodified or 0 if it differs. If the exit mode is two, unifdef exits with status zero in both cases. In all exit modes, unifdef exits with status 2 if there is an error. The exit status is 0 if the -h or -V command line options are given. DIAGNOSTICS
Too many levels of nesting. Inappropriate #elif, #else or #endif. Obfuscated preprocessor control line. Premature EOF (with the line number of the most recent unterminated #if). EOF in comment. SEE ALSO
cpp(1), diff(1) HISTORY
The unifdef command appeared in 2.9BSD. ANSI C support was added in FreeBSD 4.7. AUTHORS
The original implementation was written by Dave Yost <Dave@Yost.com>. Tony Finch <dot@dotat.at> rewrote it to support ANSI C. BUGS
Expression evaluation is very limited. Handling one line at a time means preprocessor directives split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation. Trigraphs are not recognized. There is no support for symbols with different definitions at different points in the source file. The text-mode and ignore functionality does not correspond to modern cpp(1) behaviour. February 21, 2012
All times are GMT -4. The time now is 06:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy