![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to read record by record from a file in unix | raoscb | UNIX for Dummies Questions & Answers | 1 | 05-16-2008 07:30 AM |
| Script to search a bad record in a file then put the record in the bad file | shilendrajadon | Shell Programming and Scripting | 2 | 12-28-2007 10:02 AM |
| Script to search a bad record in a file then put the record in the bad file | shilendrajadon | UNIX for Advanced & Expert Users | 1 | 12-28-2007 10:00 AM |
| splitting a record and adding a record to a file | rsolap | Shell Programming and Scripting | 1 | 08-13-2007 02:58 PM |
| Select text within matching ( ) bracket | cursive | UNIX for Dummies Questions & Answers | 4 | 04-20-2007 03:14 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
select a record from one file matching from second file using awk
I need help
![]() I have two input files and I'd like to generate a report based on the two. filea: hostname,account1,password ,account2,password hostname,account1,password hostname,account1,password ,account1,password ,account2,password repeating hostnames are blank fileb: hosta hostb hostc I need to generate a record of "hostname account password" for all hosts in fileb that occur in filea for a specific account. I.e. I want a list of root passwords for all hosts in fileb. I know the logic I want to use but don't have the scripting skills to implement it. I think the easiest way would be to use awk to fill in the blanks with the hostname of filea and then simply use a shell script to grep for each host in fileb of the new filea. The other way is to run down filea for each hostname in fileb until either the account is matched or the hostname is different and print the result. If the account does not exist for the given hostname do nothing. I'm trying to save manually doing this by scripting it thinking it would be faster but maybe I was wrong ![]() Here is the framework I came up with so far for the harder way because it would be more elegant ![]() #!/bin/sh # hosts=`cat hosts.txt` hostname="x" last="x" for name in ${hosts} do #the awk logic would come here done |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|