The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 06-06-2008
synmag synmag is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Quote:
Originally Posted by era View Post
You mean something like this?


Code:
sed -e 's/.*/^&,/' fileb | grep -f - filea

Not all grep versions support the -f option apparently, but the idea is simply to grep for anything from fileb which is in the first field of filea.
Thanks for the reply. My version does not support -f unfortunately. Looking at the code where would I specify the account name I'm looking for? Say if I want to list the host,account,password for all root accounts? Also would this work for records where the host name is blank?

To clarify the problem, filea has blanks for repeating hostnames and if say root is in a record where there is no hostname how do you derive the hostname for the record? The hostname I'm looking for is the prior non blank record.

example:

hosta,johndoe,abc123
,root,4009dlkj
hostb,janedoe,rrrrrr

if host a is in fileb the expected out put for root is

hosta,root,4009dlkj

I was trying to use awk to replace the blank with a hostname from the previous nonblank record but I kept getting errors. I couldn't even store $1 to a variable and print it as a test. I know sed is very powerful but I didn't think this could be done with one line.

I ended up doing it manually last night. At this point it's inquiring minds want to know and it might come in handy if I have to do it again.

TIA