Read file and get the data then put it in array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file and get the data then put it in array
# 1  
Old 06-27-2013
Read file and get the data then put it in array

Hi,

I have a file called "readfile" it contains below parameters

#cat readfile

word=/abc=225,/abc/cba=150 three=12 four=45 five=/xyz/yza

likewise multiple line.

From the above file, I have to read "word"

output should be like,

/abc
/abc/cba

these values need to be put in an array.
# 2  
Old 06-27-2013
to understand your req clear please more lines from input file and also the reason why it needed in array? also let us know the shell you are working on?
# 3  
Old 06-27-2013
Hi,

Thanks for quick reply,


requirement:
1. runtime a script has to read a file and get the values of "word"
here "word" may contains one or two fields separated by comma,


word=/abc=225,/abc/cba

as it has two fields, So I need to put it in an array, so that I can use each filed at a time.
# 4  
Old 06-27-2013
Try
Code:
awk '{for (i=1; i<=NF; i++) if ($i ~ /word/) {split ($i, A, "[=,]"); print A[2] " " A[4]}}' file
/abc /abc/cba

and read man bash (or whatever your shell be) on how to assign to an array.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Visit site get data and put in file for use.

I need to go to "vpnbook"vpnbook.com on the web (can't put in name yet)and open "Openvpn" tab On that page I need to get the username:vpnbook and the next line password:???????? I need to put those two in line one and two of a file "pwfile" When I have those I need to open openVPN with the... (1 Reply)
Discussion started by: tytower
1 Replies

2. Shell Programming and Scripting

Perl : Large amount of data put into an array

This basic code works. I have a very long list, almost 10000 lines that I am building into the array. Each line has either 2 or 3 fields as shown in the code snippit. The array elements are static (for a few reasons that out of scope of this question) the list has to be "built in". It... (5 Replies)
Discussion started by: sumguy
5 Replies

3. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

4. Shell Programming and Scripting

Read value of a file, remove first 2 chars and put this value in a variable

Hi i have need of read a file value with cat command and remove first 2character for example cat /sys/class/rtc/day 0x12 Remove char 12 And put this value in a variable is possible with a script thanks for help (6 Replies)
Discussion started by: enaud
6 Replies

5. UNIX for Advanced & Expert Users

filter last 24 hour data and put in new file

i have file server 1 (filesvr01acess.log) and disc server 1 (discsvr01acess.log) in unix box(say ip adress of the box 10.39.66.81) Similiarly i have file server 2 (filesvr01acess.log) and disc server 2(discsvr01acess.log) in another unix box(say ip adress of the box 10.39.66.82). Now my... (1 Reply)
Discussion started by: nripa1
1 Replies

6. Shell Programming and Scripting

Read a file and put it in HTML format

Hi, I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail. Communications Pvt Ltd Report AccountId Name Code IdBill Balance ... (3 Replies)
Discussion started by: Kattoor
3 Replies

7. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

8. 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

9. Shell Programming and Scripting

problem to read data in array

My input is a long list of data start with "#": #read_1 123456898787987 #read_2 54645646540646406 #read_3 4654564654316 . . I got a bit confusing about how to set all in an array first. And then when I run a program name "statistic_program", it will read the array in scalar and do... (24 Replies)
Discussion started by: patrick87
24 Replies

10. Shell Programming and Scripting

read a file in shell and put result in a line

Hi All, I have a to read a file and put the result in one line. The i am reading from contain the data like below. 1 signifies the beging of the new line. (6 Replies)
Discussion started by: lottiem
6 Replies
Login or Register to Ask a Question