logo       

Re: Replacing a pattern in one file by reading a string from another file: msg#00009

editors.sed.user

Subject: Re: Replacing a pattern in one file by reading a string from another file

> Thx Tim, that worked like a charm,

Glad it worked.

> Now I am getting a bit greedy, I need another guidance. I have
> done my homework on this issue since last 2 days before I
> posted this new issue

The reply came directly to me and didn't seem to go to the list.
In this case, I've got an idea that should work. However, there
are many folks on the list that are light-years beyond me when it
comes to knowing the dark corners of sed. It's best to CC: the
list when replying so that you can tap their brains too :)

> At a very high level, I am trying to parametrize the output
> file. Initially I thought I would have to deal with only one
> param and my earlier issue was that, but now I have to deal
> with many more parameters
>
> Here is the issue
> I have the parameters file which looks like this:
> file 1:
> username:SAPextract
> password:$$$$$
> Monthtoextract: October
>
> file2:
> RunasUser: $username
> RunasPsswd: $password
> RunMonth: $Monthtoextract

The general way to do this is in two phases. You use you first
file to create a sed script (assuming, as has been an issue on
the list recently, that file#1 isn't overly long), and then run
that resulting sed-script against the 2nd file. The process would
look something like

sed 's/.*/s:$&:/' file1.txt > script.sed
sed -f script.sed file2.txt > output.txt
rm script.sed

This presumes that the names and values from file1.txt don't
contain characters that would choke sed.

If you inspect the script.sed, you can see what's going on
here...the first sed statement is creating the script to be used
by the second sed statement.

With bash on Linux at least, you can create fifos on the fly that
will do this nicely in one pass for you (without the need to
clean up)

sed -f <(sed 's/.*/s:$&:/' file1.txt) file2.txt > out.txt

I don't know about other environments in which this slick little
trick might work (maybe Bash on other platforms?)

-tim







------------------------ Yahoo! Groups Sponsor --------------------~-->
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/2jUsvC/tzNLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~->

--

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/

<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/






<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise