|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
gurdeepdua:
you really are the best the best horse in stable. |
|
#4
|
|||
|
|||
|
Quote:
Thanks very much for the assist. Seems I need to brush up on redirects. -RU |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Help dealing with spaces in text files. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|