Comparison and deletion of lines between two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparison and deletion of lines between two files
# 1  
Old 02-24-2011
Comparison and deletion of lines between two files

Hi i need an help. I have two files list1 and list2, both contains the server names i want to delete the servers in list2 which were also found in list1.

for an eg

HTML Code:
list2              list1
 
oradg1            oradg4
oradg2            oradg2                            
oradg3            oradg3
oradg4            j2ee1
j2ee1              
j2ee2
j2ee3
j2ee4

i want o/p ot be like this

HTML Code:
list2 
 
oradg1
j2ee2
j2ee3
j2ee4

I new to this unix , so please help.
Thanks in advance
# 2  
Old 02-24-2011
Try this,
Code:
awk 'NR==FNR{a[$1]++;next} !a[$1]' list1 list2

# 3  
Old 02-24-2011
pravin i got below error


HTML Code:
awk: syntax error near line 1
awk: bailing out near line 1
 
SmilieSmilieSmilie
# 4  
Old 02-24-2011
If you are using solaris then use /usr/xpg4/bin/awk or nawk instead of awk
This User Gave Thanks to pravin27 For This Post:
# 5  
Old 02-24-2011
Try this shell script ,

Code:
#!/bin/bash
while read line1
do
        match=0
        while read line2
        do
                if [ $line1 ==  $line2 ]; then
                        match=1
                        break
                fi
        done <"file2"
        if [ $match -eq 0 ] ; then
                echo "$line1" 
        fi
done <"file1"

# 6  
Old 02-24-2011
Code:
comm -3 <( sort list1) <(sort list2)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking the averages of columns with deletion of some lines

Hi, I am in stage of post processing some of my results. I wanted to plot the data against the three axis x,y,z. The data file is quite complicated and i have to take the average of x, y,z over different steps of my test. A typical file look like below: Time taken:4s No.of series : 3... (6 Replies)
Discussion started by: begin_shell
6 Replies

2. Debian

Problem with files/dirs deletion

Hi, The other day i installed a PHP based CMS (modx) on my shell account and noticed that i couldn't delete any of files/dirs it created after. Also, i noticed that all that stuff is owned by username-www instead of username. I tried chown, chmod and using a PHP script to do the same wti... (4 Replies)
Discussion started by: pentago
4 Replies

3. Shell Programming and Scripting

deletion of multiple occurring files

Hi all, In the given file, what I need to do is to select double (or triple) occurring files and delete the one having smaller file size. And would like to keep the one with the big file size. 518t-rw-r--r-- 1 emily us_cms 101348458 Oct 8 16:43 vgtree_518_0_LHB.root 518t-rw-r--r-- 1... (9 Replies)
Discussion started by: emily
9 Replies

4. Shell Programming and Scripting

Operations on a file with Deletion , Modification and Insertion of lines

Hi All , Given a file , I need to delete , modify and insert lines matching certain patterns in that file using shell scripting. e.g. If a file FILE1 has following content : CUST.ABC.DEF = CUST.ABC.DEF * CUST.ABC.DEF PRINTF(CUST.ABC.DEF) CUST.ABC.DEF = mid(CUST.ABC.DEF,10.34)... (5 Replies)
Discussion started by: swapnil.nawale
5 Replies

5. Shell Programming and Scripting

Files Deletion After 20 Minutes

Hi, everyone. Could you help me with deletion of files, which are 20 minutes old. I found out how to make deletion for files in that way : find <dir> -mtime n -exec rm -rf "{}" Could you offer your suggestions. Many thanks in advance. (5 Replies)
Discussion started by: KReoN
5 Replies

6. UNIX for Dummies Questions & Answers

deletion of all lines ends with :

I have below file say temp1 BSCAJM1:HWJA10C BSCAJM1: BSCALW1: BSCALW1:GVND01B BSCALW1: BSCALW1: BSCBKNR:IJNMKTA BSCBKNR: BSCJOD1: BSCJOD1:JOD121B i want to delete all the lines ending with : and have below output BSCAJM1:HWJA10C BSCALW1:GVND01B BSCBKNR:IJNMKTA... (8 Replies)
Discussion started by: lalchand
8 Replies

7. Shell Programming and Scripting

Fake deletion of files

Hi, This is possibly an odd request to do with permissions as I seem to have tied myself up with these! I have the following directory (see below) that contains files that the 'usergrp' user needs to be able to 'delete' files from. drwxr-s--- 2 usergrp usergrp 512 16 Feb 14:37... (2 Replies)
Discussion started by: Peejay
2 Replies

8. Shell Programming and Scripting

Deletion of lines in a text file

Hi Everyone, Please help me with this. I have gone through many posts here but couldn't find what I wanted. I have a file with 79000+ lines and I want to delete lines in a pattern. I want to delete every 141st line in the file, starting from line 2000 till 50000. Please help guys. ... (8 Replies)
Discussion started by: max29583
8 Replies

9. UNIX for Dummies Questions & Answers

Deletion of log files.

We have log files dating back to 2004. I need to write an interative script that will request the user for how many months he needs to keep the log files and remove all the remaing log files after that month. Supposing we are now in June 2006 , if teh user request to keep log file for the last 3... (1 Reply)
Discussion started by: Geeta
1 Replies

10. Shell Programming and Scripting

Regarding deletion of old files

Hi, I have a list of directories which contain old files that are to be deleted. I put the list of all directories in a txt file and it is being read by a script Iam searching for the files older than 60 days using mtime and then deleting it But all the files are getting deleted... (3 Replies)
Discussion started by: Chidvilas
3 Replies
Login or Register to Ask a Question