Solved

Basic command UNIX command or script

Posted on 2013-01-31
4
393 Views
Last Modified: 2013-01-31
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
Comment
Question by:AIX25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Expert Comment

by:tel2
ID: 38841784
Hi AIX25,

Are both files already sorted alphanumerically, as they appear to be in the example?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 38841788
grep -f fileA fileB > resultfile
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 250 total points
ID: 38841794
try this

grep -f fileA fileB > newfile

the file newfile should have the relevant lines you need
0
 

Author Closing Comment

by:AIX25
ID: 38842016
They were answered minutes of each other. Thank you both!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Launch Process with NOT as Administrator 15 116
Parse DNS log 3 84
Linux "time" command output redirection 16 221
batch file problem 5 76
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question