Sponsored Content
Top Forums Shell Programming and Scripting Write filenames into an array variable Post 302629295 by amrutha0303 on Tuesday 24th of April 2012 01:08:31 PM
Old 04-24-2012
Corona,

I dont get what you mean. I have run the latest script i posted just above your post. I was able to assign the file names to the array. I am not sure how to look at the values stored in the array.

I need some help trying to print the values in the array.

-A

---------- Post updated at 12:08 PM ---------- Previous update was at 11:55 AM ----------

Hello All,

Here is the code i wrote to print the values assigned in the variable:

Code:
#!/usr/bin/env bash
cd $HOME/HY_DUMP
num=0
for filename in *.sql
do


testarray[$num]=$filename
#num=`expr $num + 1`
(( num += 1 ))
echo $num
#echo "new yo"
done
testnum=$num
num=0
echo $testnum
for filename in *.sql
do
echo ${testarray[$num]}
echo $num
(( num += 1))

done

And this is the output i am recieving:

[output]
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
25
HY_FILE_LOAD_Export.sql
0
HY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
1
HY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
2
HY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
3
HY_INDV_export.sqlHY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
4
HY_indv_PROGRAM_CWP_export.sqlHY_INDV_export.sqlHY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
5
hy_indv_service_map_export.sqlHY_indv_PROGRAM_CWP_export.sqlHY_INDV_export.sqlHY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
6
hy_prog_info_export.sqlhy_indv_service_map_export.sqlHY_indv_PROGRAM_CWP_export.sqlHY_INDV_export.sqlHY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
7
hy_program_bypass_export.sqlhy_prog_info_export.sqlhy_indv_service_map_export.sqlHY_indv_PROGRAM_CWP_export.sqlHY_INDV_export.sqlHY_INDV_PROGRAM_export.sqlHY_INDV_CONTACT_export.sqlHY_INDV_ADDRESS_export.sqlHY_FILE_LOAD_Export.sql
8
hy_program_close_export.sql
9
hy_program_service_area_export.sql
10
hy_questionaire_export.sql
11
hy_ref_table_export.sql
12
hy_security_group_export.sql
13
hy_security_grp_tbls_map_export.sql
14
hy_security_tables_export.sql
15
hy_service_area_county_export.sql
16
hy_service_area_export.sql
17
hy_truncate_tables_export.sql
18
hy_work_mgweb_load_export.sql
19
hy_work_mhmr_load_export.sql
20
hy_work_sas_load_export.sql
21
tt_batch_rank_export.sql
22
tt_cil_prog_list_export.sql
23
tt_csil_select_export.sql
24

[/output]

The wierdest thing with the output is some of the values are getting concatenated with the previous values.
Is there anyway to flush the value stored in filename after the value is being assigned to the array so that we could avoid this problem?

-A

Last edited by Scrutinizer; 04-24-2012 at 02:14 PM.. Reason: Code tags for data sample too..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Push records to array during implicit loop and write to file

NEWBIE ALERT! Hi, I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies

2. Shell Programming and Scripting

i have no understanding of how to write an array or use one, please help!

im in a basic unix class and our professor speaks broken engliash so i can never understand what exactly we are doing in class and i have no prior experience with unix. we were given an assignment to make 2 files. one to Input 10 numbers and print out the biggest number, and one to Write a script... (1 Reply)
Discussion started by: wendyshephard
1 Replies

3. Homework & Coursework Questions

i have no understanding of how to write an array or use one, please help!

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: make 2 files. one to Input 10 numbers and print out the biggest number, and one to Write a script that can check... (1 Reply)
Discussion started by: wendyshephard
1 Replies

4. Shell Programming and Scripting

Storing cutted filenames into variable

Hi, I'd like to write a script which works on various files file1.jpg, file2.jpg ..... These files are splitted and their names are something like file_.XXX. I'd like to merge them and convert them at some moment again in file.XXX also file1_1.jpg file1_2.jpg ... >file1.pdf file2_1.txt... (2 Replies)
Discussion started by: bsco
2 Replies

5. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

6. Shell Programming and Scripting

Write array contents to file

Hi, I have a bash script that currently holds some data. I am trying to write all the contents to a file called temp.txt. I am using echo ${array} > temp.txt The problem that I am experiencing is that the elements are being written horizontally in the file. I want them written... (5 Replies)
Discussion started by: Filter500
5 Replies

7. Shell Programming and Scripting

How to get filenames in a directory and write them in to a file?

I need to get the names of files which are starting with a string testfile. Also i want to create a XML file in the same location and write these file names into the XML. Ex: <path> <dir> <file>testfile1</file> </dir> <dir> <file>testfile2</file> </dir>... (4 Replies)
Discussion started by: vel4ever
4 Replies

8. Shell Programming and Scripting

Storing filenames in an array in shell script

hi, i am writing a shell script in which i read a line in a variable. FNAME="s1.txt s2.txt s3.txt s4.txt s5.txt" i want to create a array and store single file names in a array.. so the array should contain arr="s1.txt" arr="s2.txt" arr="s3.txt" arr="s4.txt" arr="s5.txt" how to... (3 Replies)
Discussion started by: Little
3 Replies

9. Shell Programming and Scripting

Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like... (2 Replies)
Discussion started by: bdeads
2 Replies
platform::shell(n)					       Tcl Bundled Packages						platform::shell(n)

__________________________________________________________________________________________________________________________________________________

NAME
platform::shell - System identification support code and utilities SYNOPSIS
package require platform::shell ?1.1.4? platform::shell::generic shell platform::shell::identify shell platform::shell::platform shell _________________________________________________________________ DESCRIPTION
The platform::shell package provides several utility commands useful for the identification of the architecture of a specific Tcl shell. This package allows the identification of the architecture of a specific Tcl shell different from the shell running the package. The only requirement is that the other shell (identified by its path), is actually executable on the current machine. While for most platform this means that the architecture of the interrogated shell is identical to the architecture of the running shell this is not generally true. A counter example are all platforms which have 32 and 64 bit variants and where a 64bit system is able to run 32bit code. For these running and interrogated shell may have different 32/64 bit settings and thus different identifiers. For applications like a code repository it is important to identify the architecture of the shell which will actually run the installed packages, versus the architecture of the shell running the repository software. COMMANDS
platform::shell::identify shell This command does the same identification as platform::identify, for the specified Tcl shell, in contrast to the running shell. platform::shell::generic shell This command does the same identification as platform::generic, for the specified Tcl shell, in contrast to the running shell. platform::shell::platform shell This command returns the contents of tcl_platform(platform) for the specified Tcl shell. KEYWORDS
operating system, cpu architecture, platform, architecture platform::shell 1.1.4 platform::shell(n)
All times are GMT -4. The time now is 02:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy