Array Retrieval Formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array Retrieval Formatting
# 8  
Old 06-16-2005
Computer

Wow it works like a champ, how cool is that? Thanks to the both of you for you help.

So I Googled around a little, and everyone shows how to do use it but not really any discription on what exactly it is. Let me see if I understand correctly.
IFS = Input Field Seperator; does that work for any kind of input like getline or a filename.sh < filename.lst etc.? Thanks again!
# 9  
Old 06-16-2005
yes, it does work on every form of input where "fields" are regarded. It will, for instance, affect the way the statement "read word1 word2 remainder" works, because a "word" is basically something surrounded by two IFS chars, whatever that may be (or BOF/EOF, of course).

Another solution to your problem is to read in your file in a loop:

Code:
(( cnt = 0 ))
cat <file> | while read line ; do
     typeset myarr[$cnt]="$line"
     (( cnt += 1 ))
done

But notice, that it is necessary to protect (by quoting) your resulting variables. Once you set $IFS back to its original value you can't rely on the array elements not being split up into words if you do not surround them with double quotes.

bakunin
# 10  
Old 06-16-2005
Right on, thanks bakunin. I am taking an alternate approach with this script. I havn't worked with functions much and arrays at all, so I am making a script entirely based on this to attempt to broaden by abilities. The script looks really tidy, and probably runs faster setup this way; rather then reading an endless amount of awk statements, for loops etc. Thanks to all for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl array formatting

Experts, I'm having problems with a portion of my perl script. I have a perl array that contains the following: Port1,circuit3,2;4 Port2,circuit1,9;6 Port3,circuit2,12;5 Port4,circuit4,11;10;3 Port5,circuit7,8;7;1 I'm trying to produce the following output: (3 Replies)
Discussion started by: timj123
3 Replies

2. UNIX for Dummies Questions & Answers

Formatting Array Output

Hello All, Q1) I have the below code but when the email was sent out all lines are merged and coming out as a single line though my printf statement has newline "\n", How do i avoid that? Q2) In my second IF statement when i introduced the backslash "\" for continuation of a line or command, i... (10 Replies)
Discussion started by: Ariean
10 Replies

3. Shell Programming and Scripting

MySQL bulk retrieval of database through html form

Have to delete this long post. Seems nobody would spent time on it. (0 Replies)
Discussion started by: yifangt
0 Replies

4. UNIX and Linux Applications

Free-text retrieval utility

Can anyone recommend an free-text retrieval utility? Open source or free preferred. Any views on say IQ-text? (0 Replies)
Discussion started by: MJDRM
0 Replies

5. Solaris

Configure Ultra for Web doc retrieval

I have an ultra 10 - running solaris 9 that I installed a few weeks ago... I am not sure how to phrase this but basically I have some html doc's that I store on the ultra but I want people to be able to access from their windows workstation on our lan... How can I do this? If you could help... (4 Replies)
Discussion started by: frustrated1
4 Replies

6. UNIX for Dummies Questions & Answers

Retrieval of deleted files

We have a situation in a large dept of programmers where critical accounting data files were deleted. Is there any way in UNIX to trace deletions and or possibly retrieve the deleted file? (14 Replies)
Discussion started by: cgardiner
14 Replies
Login or Register to Ask a Question