Sponsored Content
Top Forums Shell Programming and Scripting Help with reading file with values and updating another file Post 302465284 by agn on Friday 22nd of October 2010 03:57:40 AM
Old 10-22-2010
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.

Last edited by agn; 10-22-2010 at 05:12 AM..
This User Gave Thanks to agn For This Post:
 

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
Gearman::Task(3pm)					User Contributed Perl Documentation					Gearman::Task(3pm)

NAME
Gearman::Task - a task in Gearman, from the point of view of a client SYNOPSIS
my $task = Gearman::Task->new("add", "1+2", { ..... }; $taskset->add_task($task); $client->do_task($task); $client->dispatch_background($task); DESCRIPTION
Gearman::Task is a Gearman::Client's representation of a task to be done. USAGE
Gearman::Task->new($func, $arg, \%options) Creates a new Gearman::Task object, and returns the object. $func is the function name to be run. (that you have a worker registered to process) $arg is an opaque scalar or scalarref representing the argument(s) to pass to the distributed function. If you want to pass multiple arguments, you must encode them somehow into this one. That's up to you and your worker. %options can contain: o uniq A key which indicates to the server that other tasks with the same function name and key will be merged into one. That is, the task will be run just once, but all the listeners waiting on that job will get the response multiplexed back to them. Uniq may also contain the magic value "-" (a single hyphen) which means the uniq key is the contents of the args. o on_complete A subroutine reference to be invoked when the task is completed. The subroutine will be passed a reference to the return value from the worker process. o on_fail A subroutine reference to be invoked when the task fails (or fails for the last time, if retries were specified). No arguments are passed to this callback. This callback won't be called after a failure if more retries are still possible. o on_retry A subroutine reference to be invoked when the task fails, but is about to be retried. Is passed one argument, what retry attempt number this is. (starts with 1) o on_status A subroutine reference to be invoked if the task emits status updates. Arguments passed to the subref are ($numerator, $denominator), where those are left up to the client and job to determine. o retry_count Number of times job will be retried if there are failures. Defaults to 0. o high_priority Boolean, whether this job should take priority over other jobs already enqueued. o timeout Automatically fail, calling your on_fail callback, after this many seconds have elapsed without an on_fail or on_complete being called. Defaults to 0, which means never. Bypasses any retry_count remaining. o try_timeout Automatically fail, calling your on_retry callback (or on_fail if out of retries), after this many seconds have elapsed. Defaults to 0, which means never. $task->is_finished Returns bool: whether or not task is totally done (on_failure or on_complete callback has been called) perl v5.10.1 2009-10-05 Gearman::Task(3pm)
All times are GMT -4. The time now is 06:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy