Sponsored Content
Top Forums UNIX for Dummies Questions & Answers reading more than one variable into a for loop Post 302250803 by starsky on Friday 24th of October 2008 10:06:22 AM
Old 10-24-2008
reading more than one variable into a for loop

Hi,

I have a file (details.txt) with 3 rows of variables ie...

name postcode age

john D fr25dd 25
mark W ab122aa 22
phil C cd343bb 33

What I want to do is read down the list with a loop and add each field into a one line piece of text...

So I have a file (test1) which reads;



my name is john D. I am 25 years old..... postcode is fr25dd
my name is mark W. I am 22 years old..... postcode is ab122aa
my name is phil C. I am 33 years old..... postcode is cd343bb



I don't know how to read more than one variable at a time, so I tried splitting the file, but it dies when trying to read the second variable $j ... What's the best way to do this?

Works with just the $i variable.

What I tried....
------------------------------------------------------------------------------------------
awk < details.txt '{print $1}' > name.test
awk < details.txt '{print $2}' > postcode.test
awk < details.txt '{print $3}' > age.test


for i in `cat name.test`
for j in `cat postcode.test`
for k in `cat age.text`

do

echo "my name is $i. I am $3 years old..... postcode is $2" > test1

done

rm name.test
rm postcode.test
rm age.test
------------------------------------------------------------------------------------------
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

reading from 2 files through while loop

hi i have two files cat input.txt 123456| 43256 456482|5893242 cat data.txt xv 123456 abcd dsk sd 123456 afsfn dd df 43256 asdf ff ss 456482 aa sf 5893242 ff ff aa 5893242 aa aa i need to read inputs from input.txt and find data for data.txt. then i need to print them as a... (2 Replies)
Discussion started by: windows
2 Replies

2. Shell Programming and Scripting

while loop not reading last line

hi all, i have a while loop which i am using to read lines into an array: k=0 exec 10<file while read LINE <&10; do ARRAY=$LINE ((k++)) done exec 10>&- echo ${ARRAY} for some reason when i display the array it is not showing the last row in the file. any help appreciated. (1 Reply)
Discussion started by: npatwardhan
1 Replies

3. Shell Programming and Scripting

Not access variable outside loop when a reading a file

I am writing a shell script using the korn shell. It seems that I am only able to use local variables within a while loop that is reading a file. (I can't access a variable outside a previously used while loop.) It's been a while since I wrote shell scripts. Here is a sample cat file.txt... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies

4. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

5. Shell Programming and Scripting

How to get the modified value of variable outside the while loop reading from a file

Hi Friends , Sorry if this is a repeated question , The input file contains 5 lines , so the the values of the variables i and count should b i=5; count=15 but the variables are not updating , the value of variables showing i=0 and count =0 only.:mad: can any1 help me please. (11 Replies)
Discussion started by: babusek
11 Replies

6. Shell Programming and Scripting

for loop - reverse reading

All, Here is my for loop export CFGLIST="LIST1 LIST2 LIST3" for i in $CFGLIST do echo print $i done The output will be LIST1 LIST2 LIST3 But i want it display LIST3 LIST2 LIST1 (8 Replies)
Discussion started by: baluchen
8 Replies

7. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

8. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

9. Shell Programming and Scripting

Reading line in while loop

Hello Team, i have to read line by line in a while loop, and the input file has:. # The script will start cppunit test application to run unit tests. -LD_LIBRARY_PATH=$CPPUNIT_HOME/lib:\ +LD_LIBRARY_PATH=$VOBTAG/SS_UnitTest/lib:\ $VOBTAG/SS_BFD/BFDSCLI/build:\ ... (7 Replies)
Discussion started by: chandana hs
7 Replies

10. UNIX for Beginners Questions & Answers

Bash Variable scope - while loop while reading from a file

Cope sample1: test.sh i=0 echo " Outside loop i = $i " while do i=$(( $i + 1)) echo "Inside loop i = $i " done echo " Out of loop i is : $i " When run output : Outside loop i = 0 Inside loop i = 1 Inside loop i = 2 Inside loop i = 3 Inside loop i = 4 Inside loop i = 5 Inside... (8 Replies)
Discussion started by: Adarshreddy01
8 Replies
OpenGuides::JSON(3pm)					User Contributed Perl Documentation				     OpenGuides::JSON(3pm)

       emit_json
	   Renders the given node as JSON

       output_as_json
	   Renders the given arbitary data as JSON

NAME
OpenGuides::JSON - An OpenGuides plugin to output JSON. DESCRIPTION
Does all the JSON stuff for OpenGuides. Distributed and installed as part of the OpenGuides project, not intended for independent installation. This documentation is probably only useful to OpenGuides developers. SYNOPSIS
use Wiki::Toolkit; use OpenGuides::Config; use OpenGuides::JSON; my $wiki = Wiki::Toolkit->new( ... ); my $config = OpenGuides::Config->new( file => "wiki.conf" ); my $json_writer = OpenGuides::JSON->new( wiki => $wiki, config => $config ); # JSON version of a node. print "Content-Type: application/javascript "; print $json_writer->emit_json( node => "Masala Zone, N1 0NU" ); # Ten most recent changes. print "Content-Type: application/javascript "; print "Last-Modified: " . $self->json_timestamp( items => 10 ) . " "; print $json_writer->make_recentchanges_json( items => 10 ); METHODS
new my $json_writer = OpenGuides::JSON->new( wiki => $wiki, config => $config ); "wiki" must be a Wiki::Toolkit object and "config" must be an OpenGuides::Config object. Both arguments mandatory. emit_json $wiki->write_node( "Masala Zone, N1 0NU", "Quick and tasty Indian food", $checksum, { comment => "New page", username => "Kake", locale => "Islington" } ); print "Content-Type: application/javascript "; print $json_writer->emit_json( node => "Masala Zone, N1 0NU" ); Note: Some of the fields emitted by the JSON generator are taken from the node metadata. The form of this metadata is not mandated by Wiki::Toolkit. Your wiki application should make sure to store some or all of the following metadata when calling "write_node": postcode - The postcode or zip code of the place discussed by the node. Defaults to the empty string. city - The name of the city that the node is in. If not supplied, then the value of "default_city" in the config object supplied to "new", if available, otherwise the empty string. country - The name of the country that the node is in. If not supplied, then the value of "default_country" in the config object supplied to "new" will be used, if available, otherwise the empty string. username - An identifier for the person who made the latest edit to the node. This person will be listed as a contributor (Dublin Core). Defaults to empty string. locale - The value of this can be a scalar or an arrayref, since some places have a plausible claim to being in more than one locale. Each of these is put in as a "Neighbourhood" attribute. phone - Only one number supported at the moment. No validation. website - No validation. opening_hours_text - A freeform text field. json_maker Returns a raw Wiki::Toolkit::Plugin::JSON object created with the values you invoked this module with. make_recentchanges_json # Ten most recent changes. print "Content-Type: application/javascript "; print "Last-Modified: " . $json_writer->json_timestamp( items => 10 ) . " "; print $json_writer->make_recentchanges_json( items => 10 ); # All the changes made by bob in the past week, ignoring minor edits. my %args = ( days => 7, ignore_minor_edits => 1, filter_on_metadata => { username => "bob" }, ); print "Content-Type: application/javascript "; print "Last-Modified: " . $json_writer->json_timestamp( %args ) . " "; print $json_writer->make_recentchanges_json( %args ); json_timestamp print "Last-Modified: " . $json_writer->json_timestamp( %args ) . " "; Returns the timestamp of the RSS feed in POSIX::strftime style ("Tue, 29 Feb 2000 12:34:56 GMT"), which is equivalent to the timestamp of the most recent item in the feed. Takes the same arguments as make_recentchanges_json(). You will most likely need this to print a Last-Modified HTTP header so user-agents can determine whether they need to reload the feed or not. SEE ALSO
o Wiki::Toolkit o <http://openguides.org/> o <http://chefmoz.org/> AUTHOR
The OpenGuides Project (openguides-dev@openguides.org) COPYRIGHT
Copyright (C) 2003-2009 The OpenGuides Project. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. CREDITS
Code in this module is mostly pirated from OpenGuides::RDF, those authors deserve all the credit. Chris Prather did the pirating. perl v5.14.2 2013-01-11 OpenGuides::JSON(3pm)
All times are GMT -4. The time now is 04:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy