Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The (SORT -M) Command 1

Status
Not open for further replies.

nm9204

Technical User
Feb 11, 2003
12
0
0
GB
All,

I have 2 files with server names, and i want to compare File1 & File2 and only show the ones that are not in the other File list:

If i had a list of servers in File1:
LDNLGHAS01
LDNLGHAS02
LDNLGHAS127
LDNLGHAS128
LDNLGHAS129

And a List of servers in File2:
LDNLGHAS01
LDNLGHAS02
LDNLGHAS03
LDNLGHAS127
LDNLGHAS128
LDNLGHAS129
LDNLGHAS130

I would only like to see a list of servers that are not in File1 compared to File2 like this!!!:
LDNLGHAS03
LDNLGHAS130

Any help would be great.

Many Thanks

Nigel
 
comm -3 file1 file2

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
rather:

comm -13 file1 file2

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks for the Reply, before i try this command, what does the -13 bit mean.

Many Thanks

Nigel
 
man comm

#----------------------------------------------
OPTIONS
The following options are supported:

-1 Suppress the output column of lines unique to
file1.

-2 Suppress the output column of lines unique to
file2.

-3 Suppress the output column of lines duplicated in
file1 and file2.



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks for the info, but i forgot to mention the i have a shell engine on a windows2000 server, and -1 to -3 is not an option.

I do howerver have the -M (compare)option, which sort of works:
(sort -M file1.txt file2.txt)

File1 has:
LDNLGHAS01
LDNLGHAS02
LDNLGHAS127
LDNLGHAS128
LDNLGHAS129

And File2 has:
LDNLGHAS01
LDNLGHAS02
LDNLGHAS03
LDNLGHAS127
LDNLGHAS128
LDNLGHAS129
LDNLGHAS130

using (sort -M file1.txt file2.txt) the output will look like this:
LDNLGHAS01
LDNLGHAS01
LDNLGHAS02
LDNLGHAS02
LDNLGHAS03
LDNLGHAS127
LDNLGHAS127
LDNLGHAS128
LDNLGHAS128
LDNLGHAS129
LDNLGHAS129
LDNLGHAS130

I'm wondering if there is an other command that will sort this new output list.

Many Thanks

Nigel
 
we're apples and oranges here.

I mean 'comm' and you're saying 'sort'.

Do you have 'comm'?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
> but i forgot to mention the i have a shell engine on a windows2000 server
So is this really anything like unix at all?

I would suggest you ask your win2K scripting questions on
forum96
 
it,s not the case that i seek for win2k scripting questions, i have Tivoli installed and it comes with a shell engine,so i can use bash to write scripts, as it's on a w2k server i still get the options and switches for using bash but not all of them.

Many thanks

Nigel
 
kind of rudimentary, but maybe your system supports:

cat file1 file2 | sort | uniq -u > file3

where file3 will be the unique entries from the first two files.

Duane
 
Thanks very much for the help (vgersh99) and (Duane61) but i did find a shell command that works and its call the DIFF command. cheers

As For (Salem) this command is used on UNIX and LINIX as it's a shell Command, and having a SHell engine on my w2k machine will do the same, not win2K scripting questions, thats why i have seeked help in this FORUM (i.e. UNIX). Anyway thanx for your expert Knowledge and advice!!!!!

Nigel
 
Having a unix shell is not the same as having unix. Tivoli may well have ported bash to windows, but did they also port the rest of the standard unix programs (like comm, uniq, cat, ...) to windows as well?

Hence the confusion when you said you didn't have 'comm' in response to vgersh99's original reply.

Bash is just a much more capable replacement for the windows cmd.exe. And like all shells, when it sees a command it does not recognise, it looks around for a program of that name and tries to run that instead. Knowing that your bash is going to be looking through a win2K file system and not a unix file system is an important piece of information (since by default, everyone will assume that a unix file system will be searched).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top