Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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
Replies are listed 'Best First'.
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 avoiding work at the Monastery: (9)
As of 2015-07-28 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls