Creating array containing file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating array containing file names
# 1  
Old 11-02-2010
Creating array containing file names

I am wondering how I can save the file names (stored in $file or $fnames) in array which I can access with an index.

Code:
  alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`'

  set narg = $#argv
  while ($iarg < $narg)
   MATH iarg = $iarg + 1
   set arg = $argv[$iarg]
   set opt = ` echo $arg | awk 'BEGIN { FS="=" } { print $1 }'  \
                         | tr "[A-Z]" "[a-z]" `
   set par = ` echo $arg | awk 'BEGIN { FS="=" } { print $2 }' `

   switch ($opt)

    case "-j":
        set Asize = $par
        set widthbase = `echo $Asize | awk '{split($1,a,"/"); print a[1]}'`
        set heightbase = `echo $Asize | awk '{split($1,a,"/"); print a[2]}'`
        set optsize = 1
        breaksw

   default:
      set file = `echo $arg | awk 'BEGIN {FS="."} {print $1}'`
      set fext = `echo $arg | awk 'BEGIN {FS="."} {print $2}'`
      set fnames = "$fnames $arg"   # Store the file names
      set fexten = "$fexten $fext"   # Store the file extensions
      MATH nf = $nf + 1
    endsw

  end   # while

# 2  
Old 11-03-2010
Code:
% set files="one two three"
% set file_array = ( $files )
% echo $file_array[2]
two

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Shell Programming and Scripting

File names as array element in ksh

Hi, I have an ksh array(ARR). the elements to the array are file names. i need to go to each file in the array and manipulate the records. for name in ${files}; do ---this loop is for all the file names in the array for i in $(wc -l < $name); do --this loop is for all the records in... (20 Replies)
Discussion started by: usrrenny
20 Replies

3. Shell Programming and Scripting

How to pass an array containing file names to a sftp script?

hi, i want to pass an array parameters to a sftp script so that i can transfer each file in the array to the remote server by connecting only once to the sftp remote server. i thought of using a variable that contains list of file names separated by a space and pass the variable to the sftp... (3 Replies)
Discussion started by: Little
3 Replies

4. Shell Programming and Scripting

Dynamically creating file names from portions of another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to get... (2 Replies)
Discussion started by: jclanc8
2 Replies

5. Shell Programming and Scripting

Creating array from file

Dear community, how can I create an array from file taking only the 4th field? out.txt file is something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20So the final array should be: 4 8 12 16 20With this command I created an array with all the fields, but I need only the 4th... (13 Replies)
Discussion started by: Lord Spectre
13 Replies

6. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

7. Shell Programming and Scripting

Creating usernames from a list of names

Hello everyone, I am trying to create a script that will make usernames (last name and first letter of name - for example, James Bond = bondj). At this point, I figured out how to make a script that can read the list of names from a text file. Here is what I have: #!/bin/bash ... (5 Replies)
Discussion started by: RSpades
5 Replies

8. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

9. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies
Login or Register to Ask a Question