Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to replace string in file2 that matches first column of file1 with second column of file1

by 2teez (Priest)
on Apr 25, 2013 at 05:48 UTC ( #1030588=note: print w/ replies, xml ) Need Help??


in reply to How to replace string in file2 that matches first column of file1 with second column of file1

Something like this:

use warnings; use strict; use Inline::Files; my %name_change; while (<FILE_1>) { chomp; next if /^$/; my ( $k, $v ) = split /,/, $_; $name_change{$k} = $v; } while (<FILE_2>) { chomp; s/(uid=)(.+?),/$1$name_change{$2},/ if /uid/; print $_, $/; } __FILE_1__ anakin,james obiwan,nicol skywalker,sarah darthvader,robert __FILE_2__ DN: CN=Itmanagement,OU=Groups,O=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=anakin,OU=Users,o=uni.com DN: CN=ComputerScience,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=obiwan,OU=Users,o=uni.com DN: CN=accoutning,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=skywalker,OU=Users,o=uni.com DN: CN=management,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=anakin,OU=Users,o=uni.com
Output:
DN: CN=Itmanagement,OU=Groups,O=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=james,OU=Users,o=uni.com DN: CN=ComputerScience,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=nicol,OU=Users,o=uni.com DN: CN=accoutning,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=sarah,OU=Users,o=uni.com DN: CN=management,OU=Groups,o=uni.com ChangeType: Modify Add: uniquemember uniquemember: uid=james,OU=Users,o=uni.com

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: How to replace string in file2 that matches first column of file1 with second column of file1
Select or Download Code
Re^2: How to replace string in file2 that matches first column of file1 with second column of file1
by Not_a_Number (Parson) on Apr 25, 2013 at 06:18 UTC

    "If you tell me, I'll forget."

      And "If you show me, I'll remember."
      I simply shown the OP, a blue-print of what to do, he/she would have to build the building to completion.
      Nice one Not a Number :)

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
Re^2: How to replace string in file2 that matches first column of file1 with second column of file1
by anakin30 (Acolyte) on Apr 25, 2013 at 06:22 UTC

    Thank you so much for the reply.
    I will go through the script to understand more better
    Thanks once again

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-17 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (60 votes), past polls