UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 22nd, 2006, 05:41 PM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 70 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 12 m 53 sec
Reputation Power: 4
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

Reply With Quote
  #2  
Old March 22nd, 2006, 06:14 PM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
What OS and shell are you using?

Reply With Quote
  #3  
Old March 22nd, 2006, 06:21 PM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 70 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 12 m 53 sec
Reputation Power: 4
Quote:
Originally Posted by stanleypane
What OS and shell are you using?


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

Reply With Quote
  #4  
Old March 23rd, 2006, 08:40 AM
stanleypane's Avatar
stanleypane stanleypane is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Baltimore, MD
Posts: 208 stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level)stanleypane User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 7 h 4 m 19 sec
Reputation Power: 21
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

Reply With Quote
  #5  
Old March 24th, 2006, 05:23 AM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 70 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 12 m 53 sec
Reputation Power: 4
Quote:
Originally Posted by stanleypane
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


cheers for that dude, but that just prints /path/to/numbers/*

Reply With Quote
  #6  
Old March 24th, 2006, 05:37 AM
GlobeTrotter GlobeTrotter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 70 GlobeTrotter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 12 m 53 sec
Reputation Power: 4
Quote:
Originally Posted by GlobeTrotter
cheers for that dude, but that just prints /path/to/numbers/*


hey ignore that last post, my directory was wrong. that worked perfect. thanks again. i may be back tho

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need help splitting a string


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT