Sort differences


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort differences
# 1  
Old 05-01-2007
Sort differences

I have a file that contains

/home
/opt
/stand
/var
/usr
/tmp
/opt
/home

I need to print the lines that are unique so the output would be

/stand
/var
/usr
/tmp

and omit any filesystems that are duplicates. I searched the forums but did not find anything, although i searched on diff and comm and their must be a simlar problem out there. If anyone has a solution or a link to another thread it woudl be appreciated. It is an HP-UX system with only a posix shell.

Sean
# 2  
Old 05-01-2007
See if this would do for you:
Code:
sort input_file | uniq -u

# 3  
Old 05-01-2007
MySQL

That command worked great, i have never used the uniq command before but it was just what i was looking for thank you.
# 4  
Old 05-01-2007
Quote:
Originally Posted by insania
I have a file that contains

/home
/opt
/stand
/var
/usr
/tmp
/opt
/home

I need to print the lines that are unique so the output would be

/stand
/var
/usr
/tmp

and omit any filesystems that are duplicates. I searched the forums but did not find anything, although i searched on diff and comm and their must be a simlar problem out there.

Code:
awk '
  { ++x[$0] }
  END { for (v in x) if ( x[v] == 1 ) print v }
' FILE

Quote:
If anyone has a solution or a link to another thread it woudl be appreciated. It is an HP-UX system with only a posix shell.

A POSIX shell is more than adequate for the vast majority of shell scripting tasks.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

2. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

3. Shell Programming and Scripting

{} and ( ) differences

Can u tell the diff between the 1) $a and ${a} 2)] and ( ) 3)" " and ' ' , ` ` 4) 'a' , "a", please explain with simple example (1 Reply)
Discussion started by: mrbinoy
1 Replies

4. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

5. Shell Programming and Scripting

Differences between 2 directories

Hi, I am trying to write a script under ksh to list all the differences between two directories. For example: # ls test1 test2 I need to compare all the files under between test1 & test2. When I do diff, it only compares the diectoires but it doesn't check inside. I did do... (3 Replies)
Discussion started by: samnyc
3 Replies

6. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

7. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

8. UNIX for Dummies Questions & Answers

Differences

Hi all, I am using korn shell. I want to know what is the difference between hey and echo commands. (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

9. Solaris

Differences between Solaris 2.5 and 9

Hi Can anybody tell what are the great differences in Solaris 2.5 and 9? I am seeking information like differences in libraries, User Interface, Configuraion files, daemons, Packaging and archiving tools, Hardware supported etc. Please help me, as this is little urgent. Even if you can refer... (4 Replies)
Discussion started by: charlcy
4 Replies
Login or Register to Ask a Question