Sponsored Content
Top Forums Shell Programming and Scripting How to fetch values from a line in a file to variables in UNIX? Post 302844971 by karthikram on Tuesday 20th of August 2013 01:05:37 PM
Old 08-20-2013
Hi,

Thanks , the script worked well in ksh, now using your script each variable can be applied for each line ,
It is very helpful to me , But i am getting error while trying to use while loop or until after "eval" to get variable array's each element.
I will search the forum to get suitable result, meanwhile if anybody has solution it could be fine for me.
I should not expect more anyway i will workaround to get and if anyone knows Please do let me know.

Code:
$more test.txt
111|22|33|44|55|aa|bb|cc
dd|ee|ff|gg|ii|jj|kk|ll|mm|nn|oo|pp

Code:
$more test_script_6.ksh
#! /usr/bin/ksh
WORD=0
i=0
while IFS=$'\|' read -A WORD$((++i)); do
eval echo -e WORD$i "\\\t" $\{#WORD$i[@]} "\\\t" $\{WORD$i[@]}
echo -e "WORD2 WORD2[3]=${WORD2[3]}"
#j=0
#until [[ $j == "$\{#WORD$i[@]}" ]]; do
#echo -e WORD$i WORD$i[$j]=${WORD$i[$j]}
#j=$((j + 1))
#done
;done < test.txt

Code:
$./test_script_6.ksh
WORD1    8       111 22 33 44 55 aa bb cc
WORD2 WORD2[3]=
WORD2    12      dd ee ff gg ii jj kk ll mm nn oo pp
WORD2 WORD2[3]=gg


Code:
$more test_script_6.ksh
#! /usr/bin/ksh
WORD=0
i=0
while IFS=$'\|' read -A WORD$((++i)); do
eval echo -e WORD$i "\\\t" $\{#WORD$i[@]} "\\\t" $\{WORD$i[@]}
echo -e "WORD2 WORD2[3]=${WORD2[3]}"
j=0
until [[ $j == "$\{#WORD$i[@]}" ]]; do
echo -e WORD$i WORD$i[$j]=${WORD$i[$j]}
j=$((j + 1))
done
;done < test.txt

Code:
$ksh -x test_script_6.ksh
+ WORD=0
+ i=0
test_script_6.ksh: line 3: syntax error at line 9: `$' unexpected

tried with "while" also same error.

Thanks,
Regards,
karthikram

---------- Post updated at 01:05 PM ---------- Previous update was at 12:33 PM ----------

Hi Corona,

Thanks , i will try awk RS variable too, if this is achived and there wont be any loop again,

I wil try to come up and will post for review/suggestion.

Thanks,
Regards,
karthikram
 

10 More Discussions You Might Find Interesting

1. Programming

how do u assign the values to different variables when it is presneted in one line??

hey people.. i have a configuration file that looks like 7080 7988 net04.xxxxx.edu 20 where 20 is the number of threads in the thread pool initially. net04.xxxxx.edu is the hostname. and 7080 7988 are two ports. first one for client requests and second one for dns communication. now my... (2 Replies)
Discussion started by: SwetaShah
2 Replies

2. Shell Programming and Scripting

How to fetch data from a text file in Unix

I want to fetch passwords from a common file xxxx.txt and use it in a script. Currently the password is hardcoded so this have to be changed so that password can be fetched from text file..... Please reply asap.. Thanks (4 Replies)
Discussion started by: shikhakaul
4 Replies

3. Shell Programming and Scripting

[BASH] mapping of values from file line into variables

Hello, I've been struggling with this for some time but can't find a way to do it and I haven't found any other similar thread. I'd like to get the 'fields' in a line from a file into variables in just one command. The file contains data with the next structure:... (4 Replies)
Discussion started by: semaler
4 Replies

4. Shell Programming and Scripting

How to fetch a specific line from file

Hi, I have text file in the following strucher . The files contain hondreds of lines. value1;value2;value3;value4 I would like to get back the line with lowest date (values4 field). In this case its line number 3. groupa;Listener;1;20110120162018 groupb;Database;0;20110201122641... (4 Replies)
Discussion started by: yoavbe
4 Replies

5. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

6. Shell Programming and Scripting

How to fetch File from a URL to Unix Server?

Hello All, I wanted to get the software to be fetched from the Service Provide URL to my unix server. I tired using the mget, but resulted in error. Please take a look. $ wget -O V3-0-5-2.Solaris8-SPARC.tar.gz --http-user=hd87es3 --http-passwd=987dnja7 http://beyond.abinitio.com... (3 Replies)
Discussion started by: raghunsi
3 Replies

7. Shell Programming and Scripting

Fetch Data from File using UNIX or Perl

Hello, How All are Doing today. I have a issue, I have a file which contains the data as follow <ENVELOPE><ENVELOPE_ID>TEST</ENVELOPE_ID><ENVELOPE_EXTERNAL_ID></ENVELOPE_EXTERNAL_ID><ENVELOPE_VERSION>2</ENVELOPE_VERSION><SIResourceDefaultVersion>true</SIResourceDefaultVersion><TYPE>GS... (1 Reply)
Discussion started by: adisky123
1 Replies

8. UNIX for Dummies Questions & Answers

Getting values of 2 columns from sql query in UNIX variables

Hi, I have connected to oracle database with sqlplus -s / <<EOF select ename, age from emp where empid=1234; EOF I want to save the values of ename and age in unix shell variables. Any pointers would be welcome.. Thanks in advance!!1 Cheers :):):):) (1 Reply)
Discussion started by: gonchusirsa
1 Replies

9. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

10. Shell Programming and Scripting

Fetch the values based on a Key using awk from single file

Hi, Please help to fetch the values for a key from below data format in linux. Sample Input Data Format 11055005|PurchaseCondition|GiftQuantity|1 11055005|PurchaseCondition|MinimumPurchase|400 11055005|GiftCatalogEntryIdentifier|Id|207328014 11429510|PurchaseCondition|GiftQuantity|1... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies
monitor(3C)						   Standard C Library Functions 					       monitor(3C)

NAME
monitor - prepare process execution profile SYNOPSIS
#include <mon.h> void monitor(int (*lowpc(), int (*highpc)(), WORD *buffer, size_t bufsize, size_t nfunc); DESCRIPTION
The monitor() function is an interface to the profil(2) function and is called automatically with default parameters by any program created by the cc(1B) utility with the -p option specified. Except to establish further control over profiling activity, it is not necessary to explicitly call monitor(). When used, monitor() is called at least at the beginning and the end of a program. The first call to monitor() initiates the recording of two different kinds of execution-profile information: execution-time distribution and function call count. Execution-time distribution data is generated by profil() and the function call counts are generated by code supplied to the object file (or files) by cc(1B) -p. Both types of information are collected as a program executes. The last call to monitor() writes this collected data to the output file mon.out. The name of the file written by monitor() is controlled by the environment variable PROFDIR. If PROFDIR does not exist, the file mon.out is created in the current directory. If PROFDIR exists but has no value, monitor() does no profiling and creates no output file. If PROFDIR is dirname, and monitor() is called automatically by compilation with cc -p, the file created is dirname/pid.progname where progname is the name of the program. The lowpc and highpc arguments are the beginning and ending addresses of the region to be profiled. The buffer argument is the address of a user-supplied array of WORD (defined in the header <mon.h>). The buffer argument is used by moni- tor() to store the histogram generated by profil() and the call counts. The bufsize argument identifies the number of array elements in buffer. The nfunc argument is the number of call count cells that have been reserved in buffer. Additional call count cells will be allocated auto- matically as they are needed. The bufsize argument should be computed using the following formula: size_of_buffer = sizeof(struct hdr) + nfunc * sizeof(struct cnt) + ((highpc-lowpc)/BARSIZE) * sizeof(WORD) + sizeof(WORD) - 1 ; bufsize = (size_of_buffer / sizeof(WORD)); where: o lowpc, highpc, nfunc are the same as the arguments to monitor(); o BARSIZE is the number of program bytes that correspond to each histogram bar, or cell, of the profil() buffer; o the hdr and cnt structures and the type WORD are defined in the header <mon.h>. The default call to monitor() is as follows: monitor (&eprol, &etext, wbuf, wbufsz, 600); where: o eprol is the beginning of the user's program when linked with cc -p (see end(3C)); o etext is the end of the user's program (see end(3C)); o wbuf is an array of WORD with wbufsz elements; o wbufsz is computed using the bufsize formula shown above with BARSIZE of 8; o 600 is the number of call count cells that have been reserved in buffer. These parameter settings establish the computation of an execution-time distribution histogram that uses profil() for the entire program, initially reserves room for 600 call count cells in buffer, and provides for enough histogram cells to generate significant distribution- measurement results. For more information on the effects of bufsize on execution-distribution measurements, see profil(2). EXAMPLES
Example 1: Example to stop execution monitoring and write the results to a file. To stop execution monitoring and write the results to a file, use the following: monitor((int (*)())0, (int (*)())0, (WORD *)0, 0, 0); Use prof to examine the results. USAGE
Additional calls to monitor() after main() has been called and before exit() has been called will add to the function-call count capacity, but such calls will also replace and restart the profil() histogram computation. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
cc(1B), profil(2), end(3C), attributes(5), prof(5) SunOS 5.10 29 Dec 1996 monitor(3C)
All times are GMT -4. The time now is 06:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy