Find the answer to your Linux question:
Results 1 to 6 of 6
I have a list of 8000 servers, one server per line, in a text file. I need to remove 2000 specific server names from this file and save the remaining ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3

    Remove Multiple Strings From a File

    I have a list of 8000 servers, one server per line, in a text file. I need to remove 2000 specific server names from this file and save the remaining 6000 server names in another file.

    grep -v doesn't work because the list is too long and I get a "can't fork" error. Same thing happens with sed. Does anyone know a way to accomplish this?

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    welcome to the forum

    how about something like this?

    let A be the list 0f 8000, and B the list of
    2000 that you want to remove.

    cat B>>A # tacks B onto end of A
    sort A>C
    uniq -u C>D # writes unique items--those
    # not in both A and B, to D
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3
    I followed the instructions, but the file I ended up with has thousands of duplicate entries.

  4. #4
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    let us have 2 file samples please (short ones)
    the sun is new every day (heraclitus)

  5. #5
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3
    Ok, upon a closer inspection, I see that it did work, but in my final output, I have numerous duplicate entries. I only want one of each server name in there.

    Here an example:

    linux1044
    linux1045
    linux1045
    linux1046
    linux1046
    linux1047
    linux1047
    linux1048
    linux1048
    linux1049
    linux1049
    linux105
    linux1050
    linux1050

    I just need to get the extra ones out of the file.

  6. #6
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    feed the file to "uniq" again, without the '-u' thus

    uniq <D >E
    the sun is new every day (heraclitus)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...