![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help with awk and arrays | fusionX | Shell Programming and Scripting | 7 | 02-11-2008 06:41 PM |
| awk arrays | imonthejazz | Shell Programming and Scripting | 1 | 09-21-2007 09:29 AM |
| arrays in awk??? | craigsky | Shell Programming and Scripting | 3 | 08-27-2007 09:13 PM |
| ksh script - arrays | sidamin810 | Shell Programming and Scripting | 13 | 07-18-2005 03:07 AM |
| Two or more arrays in Awk | nitin | UNIX for Advanced & Expert Users | 1 | 12-10-2001 09:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hello all,
I browsed the forum (briefly) and I am having issues with a script I writing. I need to check a directory and see if there are files there, if so process all of them. The issues I am having is that when I create the array of files names using set -A filenames "$(ls -1 $OES_DATA_IN_DIR)" when I try to iterate through this using a for loop or a while loop I keep getting all entries. Here are the test scripts. I have 2 files in the $OES_DATA_IN_DIR directory. #! /usr/bin/ksh Filename=OFFER_INVENTORY_*.dat if [ -f $OES_DATA_IN_DIR/$Filename ] then set -A filenames "$(ls -1 $OES_DATA_IN_DIR)" typeset fname typeset -R10 del typeset -L6 delDate let count=0 while (( $count < ${#filenames[*]} )); do fname="${filenames[count]}" export fname del=$fname delDate=$del echo $fname echo $del echo $delDate let count="count + 1" done fi Here is the output oeosdev@grampian$ ksh array.sh OFFER_INVENTORY_200506.dat OFFER_INVENTORY_200507.dat 200507.dat 200507 oeosdev@grampian$ Now for a for loop #! /usr/bin/ksh Filename=OFFER_INVENTORY_*.dat if [ -f $OES_DATA_IN_DIR/$Filename ] then typeset fname typeset -R10 del typeset -L6 delDate let count=0 for filenames in "$(ls -1 $OES_DATA_IN_DIR)"; do fname="${filenames[count]}" export fname del=$fname delDate=$del echo $fname echo $del echo $delDate done fi Here is the oputput. oeosdev@grampian$ ksh array2.sh OFFER_INVENTORY_200506.dat OFFER_INVENTORY_200507.dat 200507.dat 200507 What I need the oputput to be is OFFER_INVENTORY_200506.dat 200506.dat 200507 OFFER_INVENTORY_200507.dat 200507.dat 200507 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|