Solved

Basic command UNIX command or script

Posted on 2013-01-31
4
387 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
4 Comments
 
LVL 11

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now