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 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 11:25 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
Configure Ultra for Web doc retrieval frustrated1 SUN Solaris 4 08-19-2004 01:08 AM
formatting xeron UNIX for Dummies Questions & Answers 5 03-20-2002 08:33 AM
Retrieval of deleted files cgardiner UNIX for Dummies Questions & Answers 14 01-28-2002 03:46 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-15-2005
gozer13's Avatar
Registered User
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking Array Retrieval Formatting

I have a shell script (Solaris v8 ksh) loading an array from a flat file. An exaple of that flat file is below. It contains white-spaces, and carrage returns. When I try to load the first line as a variable, it (the variable) shows up as the first field not the first line. How do you arrange an array by carrage return? I know it can be done, but can’t find anywhere that talk about it. Thanks in advance for replies, this forum rocks!

description.lst snippet ->
API Programmers Reference
Backup Procedures for Vista Plus on UNIX
The Vista Backup and Recovery Plan
Vista Plus Check Generations Usage Guide
-------------------------------------------------------------------------
shell scrip snippet->
set -A description $(cat $SHDIR/description.lst $1)
CNT=0
REPDESC=${description[$CNT]}
-------------------------------------------------------------------------
If I echo $REPDESC I get:
API
I would like it to echo:
API Programmers Reference

I have tried putting the contents of description.lst into “ “ to no avail.

Last edited by gozer13; 06-15-2005 at 01:46 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 06-15-2005
gozer13's Avatar
Registered User
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking Oh duh

OK just noticed something. If I change the:
set -A reportid $(cat $SHDIR/description.lst $1)
to
set -A reportid $(cat $SHDIR/description.lst $0)
maybe it may work. I will check real quick.
Reply With Quote
  #3  
Old 06-15-2005
gozer13's Avatar
Registered User
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking argh

nope didn't change the results. Oh well, anyone??
Reply With Quote
  #4  
Old 06-15-2005
djp djp is offline
Registered User
 

Join Date: Apr 2005
Posts: 13
The problem here is that the array is populated based on space-separated items. The only way I know to get around it is to change the spaces to something else and change them back later when you are ready to print. Not pretty.

djp
Reply With Quote
  #5  
Old 06-15-2005
Registered User
 

Join Date: Jan 2005
Posts: 682
Try this:
Code:
IFS='
'
set -A description $(cat $SHDIR/description.lst $1)
Reply With Quote
  #6  
Old 06-15-2005
djp djp is offline
Registered User
 

Join Date: Apr 2005
Posts: 13
If only I'd waited a little longer before displaying my ignorance!

Seriously, thanks for posting the answer, tmarikle. I've been needing that for awhile and it never occurred to me...

djp
Reply With Quote
  #7  
Old 06-15-2005
Registered User
 

Join Date: Jan 2005
Posts: 682
No worries.

One thing should be mentioned. IFS typically contains a space, a tab, and a newline character. You may want to save IFS's original value or typeset it in a function when changing it as it may change how your other scripting constructs tokenize lists. This way, IFS can be restored back to its original field separators.

Example:
Code:
OLD_IFS=${IFS}
IFS='
'
set -A ...
IFS=${OLD_IFS}
Thomas
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0