Sponsored Content
Top Forums Shell Programming and Scripting Help with reading file with values and updating another file Post 302465391 by mk7074 on Friday 22nd of October 2010 12:38:33 PM
Old 10-22-2010
Quote:
Originally Posted by agn
Try something like this,

Code:
$ cat /tmp/in
host=www.test.com
port=8080
binding="dynamic" or "other" or "something else"
key1=value1
key2=value2
key3=value4
policy="<wsp policyFile='mypolicy.policy' >
$ cat /tmp/in2
<file port="7001" binding="static" />
<details host="http//test.com" />
<policy node> insert value of policy here only if binding=dynamic otherwise leave it
</policy node>

</file>
$ cat test.pl
#!/usr/local/bin/perl -w

open CONFIG, '<', '/tmp/in';
open F, '<', '/tmp/in2';

while (<CONFIG>) {
        ($key, $value) = split /=/,$_,2;
        chomp($config{$key} = $value);
}

while ($line = <F>)  {
        foreach (keys %config) {
                $line =~ s/($_=)[^ ]*/$1"$config{$_}"/;
        }
        print $line;
}
close F;
close CONFIG;
$ perl test.pl
<file port="8080" binding=""dynamic" or "other" or "something else"" />
<details host="www.test.com" />
<policy node> insert value of policy here only if binding=""dynamic" or "other" or "something else"" otherwise leave it
</policy node>

</file>

Modify it to suit your needs.
Thank you for the code. It looks like you are using perl to do some processing and I checked with the box admin and he says we do not have perl installed and it is not on the list to be supported. Is there any other way using just shell scripting to achieve this task.



---------- Post updated at 09:59 AM ---------- Previous update was at 09:09 AM ----------




any suggestions?



---------- Post updated at 10:43 AM ---------- Previous update was at 09:59 AM ----------




i cannot use perl any other suggestions please?

thanks



---------- Post updated at 11:38 AM ---------- Previous update was at 10:43 AM ----------




Quote:
Originally Posted by agn
Try something like this,

Code:
$ cat /tmp/in
host=www.test.com
port=8080
binding="dynamic" or "other" or "something else"
key1=value1
key2=value2
key3=value4
policy="<wsp policyFile='mypolicy.policy' >
$ cat /tmp/in2
<file port="7001" binding="static" />
<details host="http//test.com" />
<policy node> insert value of policy here only if binding=dynamic otherwise leave it
</policy node>

</file>
$ cat test.pl
#!/usr/local/bin/perl -w

open CONFIG, '<', '/tmp/in';
open F, '<', '/tmp/in2';

while (<CONFIG>) {
        ($key, $value) = split /=/,$_,2;
        chomp($config{$key} = $value);
}

while ($line = <F>)  {
        foreach (keys %config) {
                $line =~ s/($_=)[^ ]*/$1"$config{$_}"/;
        }
        print $line;
}
close F;
close CONFIG;
$ perl test.pl
<file port="8080" binding=""dynamic" or "other" or "something else"" />
<details host="www.test.com" />
<policy node> insert value of policy here only if binding=""dynamic" or "other" or "something else"" otherwise leave it
</policy node>

</file>

Modify it to suit your needs.
cannot use perl any other suggestions please?
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading from a file and assigning values

HI I have something like this in a file ABC = 1 DEF = 2 GHI = 3 JKL = 4 MNO = 5 QRS = 6 TUV = 7 I need to assign ABC to V_abc (that is to a variable) GHI to V_ghi (that is to another variable) TUV to say V_tuv ... (6 Replies)
Discussion started by: ssuresh1999
6 Replies

2. Shell Programming and Scripting

Reading values from a file using DB2 SQL

I have some alphbetical codes in that (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

3. Shell Programming and Scripting

Reading from one file and updating other file with constant entries

Hi All, Thaks for the help in my last thread. I have one more question. I have two files with ldap entries in it. One file contains all the user LDAP parameter entries (26 MB) and other file contains only the user id's that have to be inactivated. Unix script has to read from the file that has... (8 Replies)
Discussion started by: Samingla
8 Replies

4. Shell Programming and Scripting

Reading values from a file

Hi I have a file in the following format AFUE 0. AOXI 0. VFUE 100.0 VOXI 274.601 TFUE 298. TOXI 2229.544 TMAX 2400. What I want to do is write a bash script, that use either perl/awk or sed to read the number after VFUE and VOXI (which is 100.0 and... (1 Reply)
Discussion started by: lost.identity
1 Replies

5. Shell Programming and Scripting

reading and updating property file

I have to do a read operation for a field in property file, which looks like follows: 123|xyz|datetime|count '|' is delimiter. Finally I managed to read the contents of property file using statement like cut -d"|" -f1 $PROPERTIES_FILE | tr '\n' ' ' <-- Reading first column But now I... (2 Replies)
Discussion started by: rakeshranjanscs
2 Replies

6. Shell Programming and Scripting

Reading off values from a large file

Hi, I have a large output file (star.log), with many lines of the following type *** T vavg unburnt: 723.187 / burnt: 2662.000 What I would like to do is pick the values 723.187 and 2662.000 and What I've got so far is awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF}END{print Tu, Tb}'... (6 Replies)
Discussion started by: lost.identity
6 Replies

7. Shell Programming and Scripting

Reading and Comparing values of file

Hi gurus.. Am reading a file, counting number of lines and storing it in a variable. Then am passing that variable into If loop for comparision, if the number of lines are greater than 1000 it should split a file if not it should send the file name to archive folder.. but when i execute the... (4 Replies)
Discussion started by: azherkn3
4 Replies

8. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

9. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy