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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 24th, 2004, 01:41 PM
RULost RULost is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 4 RULost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 17 sec
Reputation Power: 0
Help dealing with spaces in text files.

TIA! Any help would be appreciated...

I am trying to fill an array with a list of names that may or may not contain spaces (e.g. system_one, system two, sys -3, etc.). I am able to parse the text file and extract the names I want with the following:

cat file.txt | awk -F'\t' '{print $1}'

Which produces a list of names that contain the information I want, but I am unable to feed these into a array and maintain the whitespaces within the names. This is how I have tried to feed the array.

for X in `cat file.txt |awk -F'\t' '{print $1}'
do
ARRAY[$COUNTER]="$X"
COUNTER=$COUNTER+1
done

However, I end up with a list of names that are split on every space encountered in the names. Short of using 'tr' to replace all the spaces in the names, I can not figure out how to store them in the array properly.

Thanks,
RU

Reply With Quote
  #2  
Old October 25th, 2004, 01:25 AM
gurdeepdua gurdeepdua is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 4 gurdeepdua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try this
cat file.txt |awk -F'\t' '{print $1}' > file1.txt
while read X
do
ARRAY[$COUNTER]="$X"
COUNTER=$COUNTER+1
done < file1.txt

Regards
Guru

Reply With Quote
  #3  
Old October 25th, 2004, 04:55 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
gurdeepdua:
you really are the best
the best horse in stable.

Reply With Quote
  #4  
Old October 25th, 2004, 08:35 AM
RULost RULost is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 4 RULost User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by gurdeepdua
try this
cat file.txt |awk -F'\t' '{print $1}' > file1.txt
while read X
do
ARRAY[$COUNTER]="$X"
COUNTER=$COUNTER+1
done < file1.txt

Regards
Guru


Thanks very much for the assist. Seems I need to brush up on redirects.

-RU

Reply With Quote
  #5  
Old October 26th, 2004, 04:46 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
i really don't understand, why people insist writing such
betises.
1)
cat fname|awk ....
just for fun try
awk .... fname
2)
if you use it, why don't you let awk do the job ?
awk still splitted the data in arrays and field
3)
you say: spaces (e.g. system_one, system two, sys -3, etc.).
and you set the InputFieldSep to '\t' ???
(at the moment, i have no acces to my *nix sys, it's down
so i can||will not test your code)
IMO 'spaces' are 'spaces' not only 'tabs'
what happens if awk does not find a 'tab' ?
4)
no idea about the shell you are using and
you do NOT initialize COUNTER, poor prog style!
a lot of progs crash because of that.
5)
for what that redirect ???
6)
finally: what are you doing? the Q is really not clear!

Last edited by guggach : October 26th, 2004 at 04:49 AM. Reason: typo

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help dealing with spaces in text files.


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 2 hosted by Hostway