Sponsored Content
Top Forums Shell Programming and Scripting Variable increment (of some sort) Post 302646097 by Corona688 on Thursday 24th of May 2012 01:30:53 PM
Old 05-24-2012
Code:
for VAR in `print $SERVERLIST`

useless use of backticks. for VAR in $SERVERLIST will do.

But you don't need to run print and cut in backticks 10 times to process one line of text either. It is extremely slow to run awk/cut/sed 10 times to process 10 single bits of text -- that's like making 10 phone calls to say 10 words. I'd just split in the shell itself:

Code:
OLDIFS="$IFS" # Save the default value of the special IFS variable for later.  It controls splitting.

SERVERLIST="1:Server_1a 1:Server_1b 2:Server_2a 2:Server_2b 3:Server_3a 3:Server_3b 4:Server_4a 4:Server_4b"

IFS=": " # Split on space, or :
        set -- $SERVERLIST # $1=1, $2=Server_1a, $3=1, $4=Server_1b, etc.
IFS="$OLDIFS" # Set splitting back to normal

VAR=""

while [ "$#" -gt 0 ] # Loop until $1, $2, ... are empty.  We remove two arguments per loop.
do
        # Append new result to VAR.  If VAR was "1" before, it'll be "1 2", etc.
        VAR="$VAR $(cmd $1 ".././ServerBounce.ksh $2")"
        shift ; shift # Get rid of $1, $2, and shift down so the list starts at $1 again.
done

# $1 will be the result from the first process, $2 is the result from the second, etc.
set -- $VAR
echo "$# results in list"
echo "First is $1"
echo "Second is $2"
...


Last edited by Corona688; 05-24-2012 at 02:37 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

increment a Variable

hi, i want to increment a Variable but it doesnt work. here my codé COUNT=1 COUNT= 'expr $COUNT + 1' i've tried it in the prompt but it print me: expr: syntaxerror What does I make wrong? (4 Replies)
Discussion started by: cengiz
4 Replies

2. Shell Programming and Scripting

Increment variable stored in a file

Hi, I want to write a perl script, which will increment number stored in file. I want to do this without any file handles. I think we have to use some UNIX commands. I am not sure how to do this with file handles. Thanks, (1 Reply)
Discussion started by: solitare123
1 Replies

3. Shell Programming and Scripting

Increment of a variable

Hi All, I have a variable n that stores a number. Eg. echo $n comes out to be 120. I need to print 121 using echo command on n. Please advice. Thanks in advance !! (4 Replies)
Discussion started by: learning_skills
4 Replies

4. Shell Programming and Scripting

Increment a variable in unix bash

Hello There, I have been trying to increment the value of variable to 1, 2, 3 etc. but, it displays 1 1+1 1+1+1 ..... :wall: Could anyone help out with this? for i in *.* do s=`expr $s+1` echo $s j=$i$j mv $i $j done Any help is appreciated? (24 Replies)
Discussion started by: amrutha0303
24 Replies

5. Shell Programming and Scripting

Bash 4.0 increment variable

Hi there everyone! This is my first post so be gentle. I have a small bash script that is extracting 3 line every 3 lines. I got the AWK part but i cant do the loop part. #!/bin/bash export line=`awk 'END { print NR }' btnew` echo $line for i in {1..$line..3} #increment do echo... (2 Replies)
Discussion started by: theodorosGreece
2 Replies

6. Shell Programming and Scripting

How to increment a string variable?

Hi All, I am new to this forum and a novice at shell script. I am trying to write a script to determine each of the NIC configured on a linux system and its speed and Duplex. I came up with the following piece of code: echo `ifconfig -a | grep eth > /home/a/nic.txt` i=`awk -F, '{print... (4 Replies)
Discussion started by: pravin883
4 Replies

7. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

8. Shell Programming and Scripting

Increment date variable

hey guys, I need to incerement the date variable for instance echo `date '+%F %H:%M:00'` this produces 2014-08-02 20:05:00 -I will grant this to : $Datehour and need to assign 1 hr from now to $Datelasthour -the script time will be used to talk to DB system information. however... (4 Replies)
Discussion started by: mo_VERTICASQL
4 Replies

9. UNIX for Beginners Questions & Answers

Script to find a date variable and increment it

Hi, I have parameter file wo_location.prm which has a date variable $last_upd_date= 02032016. I need to write a unix shell script to find that variable and increment it by 1 day. The path to the file is root/dir_lc/shared/param/wo_location.prm and the variable is $last_upd_date. Any... (2 Replies)
Discussion started by: isenhiem
2 Replies
ADDBDDVAR(3)							   BDD FUNCTIONS						      ADDBDDVAR(3)

NAME
addbddvar - adds a new variable in the bdd system. ORIGIN
This software belongs to the ALLIANCE CAD SYSTEM developed by the ASIM team at LIP6 laboratory of Universite Pierre et Marie CURIE, in Paris, France. Web : http://asim.lip6.fr/recherche/alliance/ E-mail : alliance-users@asim.lip6.fr SYNOPSYS
#include "bdd101.h" bddnode *addbddvar( BddSystem, Variable ) bddsystem *BddSystem; bddvar Variable; PARAMETERS
BddSystem The bdd system. Variable The variable number. DESCRIPTION
addbddvar creates a new variable, with the number Variable, in the bdd system BddSystem. If a null pointer is given, the default bdd sys- tem is used. RETURN VALUE
addbddvar returns a pointer to the bdd node of the new variable. ERRORS
"no more variables, error !" There is no variable number left. "variable xxx out of range, error !" The Variable parameter must be less or equal to the BddSystem->NUMBER_VAR field. EXAMPLE
#include "bdd101.h" bddsystem *BddSystem; bddnode *BddNode; BddSystem = createbddsystem( 100, 1000, 100, 50000 ); BddNode = addbddvar( (bddsystem *)0, 0 ); destroybddsystem( (bddsystem *)0 ); SEE ALSO
bdd(1) BUG REPORT
This tool is under development at the ASIM department of the LIP6 laboratory. We need your feedback to improve documentation and tools. ASIM
/LIP6 October 1, 1997 ADDBDDVAR(3)
All times are GMT -4. The time now is 02:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy