Placing lines file in array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Placing lines file in array
# 1  
Old 10-19-2006
Placing lines file in array

Hiya I am fairly new to UNIX and have been asked to write some scripts....

I am working in the korn shell. What I am trying to do is to go through a delimited file:

Testingline1;test;test
Testingline2;test;test

and place the lines into an Array so:

Array[1] = Testingline1;test;test
Array[2] = Testingline2;test;test
etc.etc.

Any ideas??? Cheers!!

Regards,

Thomas
# 2  
Old 10-19-2006
Code:
i=0
while read str
do
arr[$((i=i+1))]=$str
done<file

# 3  
Old 10-19-2006
Hi, thanks a million for the quick help!!

The array is created, however when I read from the array it looks like:

print ${arr[1]}
Testingline1;test;test: not found


Do you know how I can get rid of the not found thing??

Again thanks for your help! Thomas
# 4  
Old 10-19-2006
use printf or echo
# 5  
Old 10-19-2006
Quote:
Originally Posted by anbu23
use printf or echo
...because your shell is not KSH and probably BASH.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

2. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

3. Shell Programming and Scripting

Put lines of a file in an array with awk

Hello, Is there any way in awk to put every line of a file in an array and so we can like this print the line we want. For example, if we have this file aaa eee bbb fff ccc ggg ddd hhh So we can print to the output the 3rd line only ccc ggg If it is possible, please put the... (7 Replies)
Discussion started by: rany1
7 Replies

4. Shell Programming and Scripting

NAWK array to store lines from huge file

Hi, I would like to clarify about the NAWK array to store multiple lines from huge file. The file is having an unique REF.NO, I wants to store the lines (it may be 100+ lines) till I found the new REF.NO. How can I apply NAWK - arrays for the above? Rgds, sharif. (1 Reply)
Discussion started by: sharif
1 Replies

5. Shell Programming and Scripting

Need to parse file "x" lines at a time ... awk array?

I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line: Column 1 is a common number for the entire file and all devices in that file Column 2 is a unique device number Column 3 is... (7 Replies)
Discussion started by: STN
7 Replies

6. Shell Programming and Scripting

Placing Duplicate Lines per section into another file

Hello, I need help in putting duplicate lines within a section into another file. Here is what I'm struggling with: Using this file “data.txt”: ABC1 012345 header ABC2 7890-000 ABC3 012345 Header Table ABC4 ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 <= dup need to remove ABC5... (4 Replies)
Discussion started by: petersf
4 Replies

7. Shell Programming and Scripting

placing a string

Hi, I have a small requriement to change a part of string in a sentence starting with "ho". For E.g I am having the following statements: I want to go to home,beach. I will never go to that horrible,place. Now I want to replace the string starting with "ho" in the above 2... (3 Replies)
Discussion started by: yoursdavinder
3 Replies

8. Solaris

Placing a config file

Hi all, I need to place a custom configuration file for a script/program that will likely be sitting in /usr/sbin, but I am unsure of exactly where to place it. In RHEL was told the config file should be in /etc/sysconfig, but no such directory exists in Solaris. Will my config file simply sit... (5 Replies)
Discussion started by: Rocket2DMn
5 Replies

9. UNIX for Dummies Questions & Answers

removing a line from a file and then placing into another file

grep `whoami` $1 >> file this lets me take out the username from a file and then i move it to a file but i need it to do one step at a time because i want the occurences to be numbered like 1)HOME=/home/joe.bloggs 2)LOGNAME=joe.bloggs instead of just HOME=/home/joe.bloggs... (1 Reply)
Discussion started by: iago
1 Replies

10. Cybersecurity

Placing a IP ban

Hello, i have some troubles with someone who keeps posting porno links on my website ;) I warned him because of it but since he only seems to like the attention i wanted to give him an IP ban. Anyone knows how i can place an IP ban with telnet on my unix server? (3 Replies)
Discussion started by: Martijn v/d Meu
3 Replies
Login or Register to Ask a Question