It is currently Tue, 30 Nov 2021 18:15:40 GMT



 
Author Message
 Reading records from file and inputting in a template
Hi
    Iam newbie and Iam stuck up with this problem. I have these 2
files. demodat.dat and input.dat
demodat.dat
  Field1     Field2
  1          2
  2          3
  3          4
  4          5

input.dat
  constant_value
  constant_value
  1 (<Field1>)
  2 (<Field2>)
constant_value

        I have to read the records from demodat.dat and enter the
fields in input.dat in a particular format. I have to create multiple
input.dat files equalling the number of records in demodat.dat. How do
I do this.

Your help is appreciated.

Srinivasan



 Tue, 09 Oct 2007 10:20:34 GMT   
 Reading records from file and inputting in a template

   What part of it is giving you problems? What have you tried? What
   shell are you using?

   Basically, you will read the records from demodat.dat (use a "while
   read" loop), and print them out in the new format (using echo or
   printf).

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2005, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Tue, 09 Oct 2007 10:32:25 GMT   
 Reading records from file and inputting in a template

I think I have an idea what you want... If you are using bash or bourne
shell you could use a while loop something like (the printf should all be
one line):

x=0

while read a b c
do
        if [ "$a" != "Field1" ]
        ((x++))
        printf "constant_value\nconstant_value\n1 $a\n2
$b\nconstant_value\n" > input$x.dat

done < demodat.dat



 Tue, 09 Oct 2007 11:06:57 GMT   
 Reading records from file and inputting in a template

there should be a "then" somewhere around here someplace (geez, I sould not
do these things off the top of my head!!

and a "fi" here! I should also say that this is off the top of my head and I
didn't test it but I hope it gets you going the right direction...

- Show quoted text -



 Tue, 09 Oct 2007 11:16:52 GMT   
 
   [ 4 post ] 

Similar Threads

1. Create Files Based On Input Records

2. Reading a file and placing records into variable(s)

3. metamail: Can't read input file (ELM 2.4 PL24)

4. reading input from a file

5. read input from a file

6. reading from a file or stadar input

7. Grabing input from a keyboard while reading from a file

8. Read from input file, and compare

9. Reading a line from an input file.

10. Displaying questions form a file and reading the user input


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software