• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Basic command UNIX command or script

I have a flat file (fileA) with a list of server names. And I have another file (fileB) with a list of server names plus system accounts. I want every line in fileB that its server is not referenced in fileA to be removed. fileB has hundreds of more server names than what is listed in fileA. I need to only have the server names listed in fileA to be in fileB. And of course, do not to change any of the information after the server name in fileB. Please help and let me know if you need me to clarify anything.

Sample of fileA:

serverA
serverB
serverC
serverD
etc...

Sameple of fileB:

serverA:adm
serverA:bin
serverA:root
serverB:adm
serverB:bin
etc...
0
AIX25
Asked:
AIX25
2 Solutions
 
tel2Commented:
Hi AIX25,

Are both files already sorted alphanumerically, as they appear to be in the example?
0
 
woolmilkporcCommented:
grep -f fileA fileB > resultfile
0
 
omarfaridCommented:
try this

grep -f fileA fileB > newfile

the file newfile should have the relevant lines you need
0
 
AIX25Author Commented:
They were answered minutes of each other. Thank you both!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now