The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 03:25 PM
array ccp Shell Programming and Scripting 3 02-26-2008 03:19 AM
I need help with an array! djsal Shell Programming and Scripting 1 11-28-2007 11:26 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 09:42 AM
Do I need an array here? TheCrunge Shell Programming and Scripting 5 04-19-2005 04:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2007
maximas maximas is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 11
array

hi to all ....
i have txt file , tat contains list of file name ... i hav to put it into the array ..
say list.txt
in tat
kay.ldf
hak.ldf
warper.ldf
like tat

thanks
  #2 (permalink)  
Old 10-08-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805

Code:
#!/bin/ksh
set -A array `awk '{printf("%s ", $0)}' list.txt`

  #3 (permalink)  
Old 10-08-2007
pinky pinky is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 33
Hey

I am also trying to get this
How can we read the values from array after storing the text file into an array

Thanks
  #4 (permalink)  
Old 10-08-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Simple Ex in ksh:

Code:
> ARRAY[1]="HOLA"
> ARRAY[2]="ADIOS"
> i=1
> j=2
> echo "${ARRAY[${i}]} ${ARRAY[${j}]}"
HOLA ADIOS

  #5 (permalink)  
Old 10-08-2007
pinky pinky is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 33
Hi Klashxx
How u doing thanks for the answer

My script is this

#!/usr/bin/ksh
DIRNAME=`dirname $0`
export columnIdFile="colids.txt"
LOGFILE=$DIRNAME/cvs_users_defaults.log
TIME=`date`
#checks to see if the log files is present, if not then creates it
if [ -a $DIRNAME/cvs_users_defaults.log ]
then
:
else
touch $DIRNAME/cvs_users_defaults.log
fi


#Checking to see if a data file(colids.txt) exists for a load.
if [ -a $DIRNAME/$columnIdFile ]
then
INCOLFILE=$columnIdFile;
echo "Using file $INCOLFILE as input for column id";
echo " ";
echo "Started Process on $TIME" >> $LOGFILE
echo "Calling procedure to initialize users"


for colId in `cat $INCOLFILE`
do
echo "Storing User Defaults for User " $colId >> $LOGFILE

integer i=0
awk '{print $1}' colids.txt | while read item; do
myarray[$i]=$item
i=$i+1
done

integer j=0
if [[ $j -lt 5 ]]; then
print ${myarray[j]}
echo "${myarray[${j}]}"
j=$j+1
fi
done
#Here I am trying to print or echo the values in the array myarray but #couldnot get the values
#Is there something wrong I am doing Can you plz help me out



#rename the file after processing
logtime=`date "+%y%m%d%H%M%S"`
newUserFile="cvs_users_processed_"$logtime".txt"
# mv $userFile $newUserFile

echo "Ending process of setting user defaults at $TIME " >> $LOGFILE
echo "Check the log file at $LOGFILE"
exit 0
else
#IF "custsoncologyusers.txt" file does not exist in DIRNAME then end grace
fully
echo "No user default file ($userFile) is available to load"
echo "No user default file ($userFile) is available to load" >> $LOG
FILE
echo "Ending user default process with a return code 0 at $TIME" >> $LOG
FILE
exit 0
fi


Thanks
Pinky
  #6 (permalink)  
Old 10-08-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Ok , try this (ksh):


Code:
i=0
awk '{print $1}' colids.txt | while read item
                                      do
                                           myarray[${i}]=${item}
                                           (( i+= 1 ))               
                                      done

j=0
while (( j < i ))
do
     echo "${myarray[${j}]}"
      (( j += 1 ))
done

Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0