Sponsored Content
Top Forums Shell Programming and Scripting How to fetch values from a line in a file to variables in UNIX? Post 302846249 by karthikram on Friday 23rd of August 2013 09:25:22 AM
Old 08-23-2013
Hi , Thanks , Now i understood that through shell it is not possible to make loop in main variable decomposing it to arrays of elements inside that each array further fetching array as array is not possible,

Please correct me if i am wrong this kind of multidimensional array and nested concept is available in PERL right.

I figured it out my script, Please let me know your suggestion or advise, how better this can be written.

Code:
$more test_script_8.ksh
#! /usr/bin/ksh

awk 'BEGIN{RS="\n";
FS="|";
}
{
print "<TR>";
for (i = 1; i <= NF; i++)
print "<TD>" $i "</TD>";
print "</TR>";
print "\n";
}' test.txt

Code:
$./test_script_8.ksh
<TR>
<TD>111</TD>
<TD>22</TD>
<TD>33</TD>
<TD>44</TD>
<TD>55</TD>
<TD>aa</TD>
<TD>bb</TD>
<TD>cc</TD>
</TR>


<TR>
<TD>dd</TD>
<TD>ee</TD>
<TD>ff</TD>
<TD>gg</TD>
<TD>ii</TD>
<TD>jj</TD>
<TD>kk</TD>
<TD>ll</TD>
<TD>mm</TD>
<TD>nn</TD>
<TD>oo</TD>
<TD>pp</TD>
</TR>


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
break(1)							   User Commands							  break(1)

NAME
break, continue - shell built-in functions to escape from or advance within a controlling while, for, foreach, or until loop SYNOPSIS
sh break [n] continue [n] csh break continue ksh *break [n] *continue [n] DESCRIPTION
sh The break utility exits from the enclosing for or while loop, if any. If n is specified, break n levels. The continue utility resumes the next iteration of the enclosing for or while loop. If n is specified, resume at the n-th enclosing loop. csh The break utility resumes execution after the end of the nearest enclosing foreach or while loop. The remaining commands on the current line are executed. This allows multilevel breaks to be written as a list of break commands, all on one line. The continue utility continues execution of the next iteration of the nearest enclosing while or foreach loop. ksh The break utility exits from the enclosed for, while, until, or select loop, if any. If n is specified, then break n levels. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be exited. The continue utility resumes the next iteration of the enclosed for, while, until, or select loop. If n is specified then resume at the n- th enclosed loop. If n is greater than the number of enclosing loops, the outermost enclosing loop shall be used. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words that follow a command preceded by ** that are in the format of a variable assignment are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign, and also that word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), exit(1), ksh(1), sh( 1), attributes(5) SunOS 5.10 17 Jul 2002 break(1)
All times are GMT -4. The time now is 10:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy