Solved

Basic command UNIX command or script

Posted on 2013-01-31
4
392 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

839 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