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 ...
- 10-07-2009 #1Just 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?
- 10-07-2009 #2Linux 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 Dthe sun is new every day (heraclitus)
- 10-07-2009 #3Just Joined!
- Join Date
- Oct 2009
- Posts
- 3
I followed the instructions, but the file I ended up with has thousands of duplicate entries.
- 10-08-2009 #4Linux 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)
- 10-08-2009 #5Just 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.
- 10-09-2009 #6Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
feed the file to "uniq" again, without the '-u' thus
uniq <D >Ethe sun is new every day (heraclitus)


Reply With Quote