|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help splitting a string
hey folks, i started learning perl a couple of weeks ago and assumed shell scripting would be similar, i was wrong. nothing seems to work as it would in perl.. ok
ok i need to read from a directory say called numbers and in numbers is say one.txt, two.txt, three.txt etc... i need to read the entire directory into say a normal string, then seperate this string into individual elements in an array which will be something like one.txt, two.txt etc... i'v tried a few things to date, even having problems with the split function. i know this is probably simple but bare with me folks, new to this.. thanks in advance guys ciaran |
|
#2
|
||||
|
||||
|
What OS and shell are you using?
|
|
#3
|
|||
|
|||
|
Quote:
hey man, in work im using just a basic Unix OP system, at home im using that cygwin shell over windows. most commands work tho. not sure what shell it is. sh or bash but thats a guess. i have it all done fine in perl but perl is kinda like java ,well to me anyway, and therefore easy enough. i'v a good bit of java experience from previous years ciaran |
|
#4
|
||||
|
||||
|
This will work for bash:
Code:
for i in /path/to/numbers/*
do
arr=( "${arr[@]}" "$i" )
done
Then you can iterate through the array like so: Code:
for (( i = 0 ; i < ${#arr[@]} ; i++ ))
do
echo ${arr[$i]}
done
|
|
#5
|
|||
|
|||
|
Quote:
cheers for that dude, but that just prints /path/to/numbers/* ![]() |
|
#6
|
|||
|
|||
|
Quote:
hey ignore that last post, my directory was wrong. that worked perfect. thanks again. i may be back tho ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Need help splitting a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|