Removing lines from one list from another list.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing lines from one list from another list.
# 1  
Old 07-01-2010
Removing lines from one list from another list.

Hello,

I was wondering if there was an easy way to take lines from a single-column list, and remove them from a second single-column list. For example, I want to remove the contents of list 1 from list 2. How would I do this?

Contents of list 1:

Code:
server1a
server2b
server3c
server4a
server5qb
server6ocd

Contents of list 2"
Code:
server1a
server2b
server3c
server4a
server5qb
server6ocd
server7dgw
server8sg
server9be
server10zt
server11w
server12t
server13f

# 2  
Old 07-01-2010
Hi

Assuming your list1 is in file1, list2 in file2

Code:
grep -v -f file1 file2

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 07-01-2010
Thank you. I didn't know it was that simple.

---------- Post updated at 01:25 PM ---------- Previous update was at 12:18 PM ----------

Also the comm command:

Print all lines that appear in file2 but not in file1 (in other words, print column 2):

Code:
 comm -13 file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing my name from Send From List

For some unknown reason, to me anyhow, every time I send out mail to all the users it keeps showing my name first instead of the email address name I am using. Not sure what I can delete at the moment as it all works as shown in the code# #!/bin/bash # This file must be amended to suit the... (2 Replies)
Discussion started by: nobbyall
2 Replies

2. Shell Programming and Scripting

Removing non-unique prefixed lines from a list

Not quite sure how to explain what I need to do (or how to title the post!) so will try and show it! Basically I have a list of 'modules' which takes the form seen below, where there can be a module name, module type and module version (a module may not have each of those and could in theory... (2 Replies)
Discussion started by: chrissycc
2 Replies

3. UNIX for Dummies Questions & Answers

Removing path name from list of file names

I have this piece of code printf '%s\n' $pth*.msf | tr ' ' '\n' | sort -t '-' -k7 -k6r \ | awk -F- '{c=($6$7!=p&&FNR!=1)?ORS:"";p=$6$7}{printf("%c%s\n",c,$0)}' When I run it I get /home/chrisd/tatsh/branches/terr0.50/darwin/n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf... (8 Replies)
Discussion started by: kristinu
8 Replies

4. UNIX for Dummies Questions & Answers

Appending lines from an existing list to each line in another existing list

Evening all ! I would like to ask your expertise on how to accomplish the following ; I have 2 lists, and would like each line from list2 to be appended to each line in list1, resulting in list3 ; List1; alpha beta charlie List2; one two three (4 Replies)
Discussion started by: TAPE
4 Replies

5. UNIX for Dummies Questions & Answers

Help removing multiple lines from one file with a list from a second file!

I am trying to remove the lines listed in example File A from File B to achieve File C. Both files are much larger than the examples below. (File B has up to 6,000 lines). I have searched the forums and I have not been able to find an answer to this particular question. I tried grep -v -f... (2 Replies)
Discussion started by: pezziza
2 Replies

6. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

7. Shell Programming and Scripting

Removing character from list line (at the end)

Hi, I have file as shown below. abc, def, abc, xyz, I have to remove ',' from end of last line (xyz,). How can I do that with single command? Is it possible or I have to iterate through complete file to remove that? - Malay (2 Replies)
Discussion started by: malaymaru
2 Replies

8. UNIX for Dummies Questions & Answers

Removing a specific word from a created list

I am working on a script that prompts a user name and creates a list in a username.dat file. Furthermore, I have created a sorted_username.dat file. My question is this: My script uses the word "finished" != finished to break the while loop. How can I avoid having the word "finished" show up in... (5 Replies)
Discussion started by: erest8
5 Replies

9. Shell Programming and Scripting

Removing duplicate files from list with different path

I have a list which contains all the jar files shipped with the product I am involved with. Now, in this list I have some jar files which appear again and again. But these jar files are present in different folders. My input file looks like this /path/1/to a.jar /path/2/to a.jar /path/1/to... (10 Replies)
Discussion started by: vino
10 Replies

10. Shell Programming and Scripting

removing a column from list

What I am trying to do is figure out how to remove a column from a list in a file, or from the command line. The opposite of cut -cX-Y file1 The file contains (result of who command) jhabi0 pts/ta Oct 8 16:22 llemo0 pts/1 Oct 8 15:30 rgood0 pts/2 Oct ... (3 Replies)
Discussion started by: jxh461
3 Replies
Login or Register to Ask a Question