Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to read parse data from two file to generate one one file

Reply
Thread Tools

how to read parse data from two file to generate one one file

 
 
Asif Iqbal
Guest
Posts: n/a
 
      08-06-2009
#!/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:12346:70006B 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





--
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
parse the data and generate report in excel formate surajtheesun@gmail.com Java 1 07-17-2007 12:21 PM
how to parse data between two date ranges perl_help_needed Perl Misc 11 08-10-2005 08:00 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57