# How to read parse data from two file to generate one one file

**URL:** <https://www.ruby-forum.com/t/how-to-read-parse-data-from-two-file-to-generate-one-one-file/173313>\
**Category:** Ruby\
**Created:** [August 6, 2009, 6:48pm UTC](https://www.ruby-forum.com/t/how-to-read-parse-data-from-two-file-to-generate-one-one-file/173313 "2009-08-06T18:48:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asif\_Iqbal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c0e974/32.png) [@Asif\_Iqbal](https://www.ruby-forum.com/u/Asif_Iqbal)\
**Post date:** [August 6, 2009, 6:48pm UTC](https://www.ruby-forum.com/t/how-to-read-parse-data-from-two-file-to-generate-one-one-file/173313/1 "2009-08-06T18:48:22Z")

</div>

#!/usr/bin/ruby

ARGF.each do |line|  
sunetid, tmp, uid, gid, name, homedir, shell = line.split(/:/)  
puts " user { “” + sunetid + “”:"  
puts " ensure =\> “present”,"  
puts " uid =\> “” + uid + “”,"  
puts " gid =\> “” + gid + “”,"  
puts " comment =\> “” + name + “”,"  
puts " home =\> “” + homedir + “”,"  
puts " shell =\> “” + shell.chomp + “”,"  
puts " }"  
puts “”  
end

This file take the a password file and generate some output per user.

How do I feed it passwd and shadow files and generate  
a file per user with another key =\> value like password =\> ‘hashkey  
from shadow’  
along with the key =\> value then it already generates?

So instead of the current output like

```
user { "dbbkp":
    ensure => "present",
    uid => "12346",
    gid => "70006",
    comment => "DB Backup User - See rsync in cron",
    home => "/home/dbbkp",
    shell => "/usr/local/bin/bash",
}

```

I want it to generate an output like this

```
   user { "dbbkp":
    ensure => "present",
    uid => "12346",
    gid => "70006",
    shadow => "iaUGiJld2XMKM" # it will get that value from shadow 

```

file  
comment =\> “DB Backup User - See rsync in cron”,  
home =\> “/home/dbbkp”,  
shell =\> “/usr/local/bin/bash”,  
}

here passwd file entry looks like this

dbbkp:x:12346:70006:DB Backup User - See rsync in  
cron:/home/dbbkp:/usr/local/bin/bash

and shadow file entry looks like this

dbbkp:iaUGiJld2XMKM:::::::

Thanks for the help
