Counting up a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting up a variable
# 1  
Old 07-17-2007
Counting up a variable

Hello,

I am trying to write a shell script, but i encountered a problem I cant solve alone so I hope you guys can help me. The situation is:

I have a script file and a config file, in my config file I set some Variables:
for example:
destination=(xp, xq, xt)
username=testor
password=testian
file1=html/de/sa_logs.php
file2=html/fr/frappi

the amount of files can go between 1 and xy.

Now the part of the scriptfile i have problems with:
i=1
b=1
while [ $i -le ${#destination[*]} ]
do
echo i ist $i
i=`expr $i + 1`
while [ $b -le ${lineCount} ]
do
t=${file$b} <<-- Here it should get me html/de/sa_logs.php for the first run (b=1) and html/fr/frappi for the second run (b=2)
temp=$t
path=${sourcepath}${temp}
echo ${path}
b=`expr $b + 1`
done
b=1
done
What i need to do is combine file and $b so that the scrip still knows i am talking about the file1, file2,file3,filexy variables and not just some text. No Idea how I can do that. Sorry for my english it isnt my native language.

Hope you can help
# 2  
Old 07-17-2007
You can use arrays in a loop to get the filenames, it's even better to put the filenames in a file.
To loop through an array you can do something like this:

Code:
file[1]=html/de/sa_logs.php
file[2]=html/fr/frappi

sourcepath="/home/"

for name in ${file[@]}
do
	path="$sourcepath""$name"
	echo $path
done

To read the names from a file "filenames":

Code:
sourcepath="/home/"

while read name
do
	path="$sourcepath""$name"
	echo $path
done < filenames


Regards
# 3  
Old 07-18-2007
Thank you very much for your reply, it works now.

good day
# 4  
Old 07-18-2007
if you have a file with variables

x=y
y=twenty
z="(1,2,3)"


you can just dot them in.

. varfile

and these variables will be instantiated to the values given, easy.

is that what you mean?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grouping and counting

Hello, I would like to group/sort a file of records by a particular field and then count how many records belong in that grouping. For example say I have the following data: 1234|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|AA ABCD|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|AA EFGH|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|BB... (14 Replies)
Discussion started by: Nik44
14 Replies

2. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies

3. UNIX for Dummies Questions & Answers

counting?

Hi all, I promise this is my very last dumb question.. but how to you count how many unique names you have. My dataset is: >Bac1 afdsgrr >Bac4 egege >Bac8 dgrjh >Bac1 afdsgrr >Bac1 afdsgrr >Bac8 dgrjh What i want to know is that how many unique names there is, so the output would... (3 Replies)
Discussion started by: Iifa
3 Replies

4. Shell Programming and Scripting

Data counting

I have a large tab delimited text file with 10 columns for example chrM 412 A A 75 0 25 2 ..,AGAATt II chrM 413 G G 72 0 25 4 ..t,,Aag IIIH chrM 414 C C 75 0 25 4 ...a,.. III2 chrM 415 C T 75 75 25 4 TTTt,,,ATC III7 At... (4 Replies)
Discussion started by: Lucky Ali
4 Replies

5. Shell Programming and Scripting

Alphabet counting

I have a text file in the following format CCCCCGCCCCCCCCCCcCCCCCCCCCCCCCCC AAAATAAAAAAAAAAAaAAAAAAAAAAAAAAA TGTTTTTTTTTTTTGGtTTTTTTTTTTTTTTT TTTT-TTTTTTTTTCTtTTTTTTTTTTTTTTT Each row/line will have 32 letters and each line will only have multiple occurrences of 2 letters out of a pool... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

7. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

8. Shell Programming and Scripting

Counting number of commas(,) in a variable

Hi all, I am having problems counting commas (,) from a variable in shell scripting.. the variable contains similiar to: ID@NAME@DESCRIPTION,ID@NAME@DESCRIPTION, ..... It can go on and on.. So i need to count the number of sets i.e.( ID@NAME@DESCRIPTION is one set) and process the... (4 Replies)
Discussion started by: faelric
4 Replies

9. Shell Programming and Scripting

need help with counting of files then pass number to variable

hi all, i'm trying to pass a count of files to a variable thru these set of codes: sh_count=$(ls -1 fnd_upload_LV*.* |wc -l) problem is if no files matches that, it will give an error "ls: fnd_upload_LV*.*: No such file or directory". how do i avoid having the shell script show that... (2 Replies)
Discussion started by: adshocker
2 Replies

10. Shell Programming and Scripting

Counting string of a variable

Hi, There is a variable f_name, it store some file names. Value of f_name=a.sql b.sql c.sql....... like this. want to count how many file name the var f_name stores. Without using loop is there any command to count that. (5 Replies)
Discussion started by: Dip
5 Replies
Login or Register to Ask a Question