Deleting Multiple Lines in Hosts File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting Multiple Lines in Hosts File
# 1  
Old 02-03-2011
Deleting Multiple Lines in Hosts File

Hello all,

I'm using the Bash shell on Solaris 8.
Please can someone tell me how I can delete multiple lines in the hosts file?
I have a list of hosts that I want to quickly delete in the hosts file, but I'm looking for a quicker way than using VI to delete the lines one by one.

Regards, Wynford
# 2  
Old 02-03-2011
put the host(s) in a file 1 per line then
Code:
cat /etc/hosts |grep -v -f <the file created> >> new file name

then cp the new file over the old hosts file after a backup of the hosts file.

Last edited by Scott; 02-05-2011 at 08:32 AM.. Reason: Code tags
# 3  
Old 02-03-2011
Hi there, I tried your suggestion but I got the following:

Code:
cat hosts | grep -v -f /tmp/temp_hosts.txt >> /tmp/new_hostsfile.txt

grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
Broken Pipe
# 4  
Old 02-03-2011
odd grep on AIX and Linux have the pattern file option:
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.

ok solaris is odd man out....
it shows this as having the file patteren match
/usr/xpg4/bin/grep
or fgrep

try with one of those.
# 5  
Old 02-03-2011
Hi there, it's working now.

I used "egrep" with the "-f" option instead of just "grep".
Thanks very much for your help.

Regards, Wynford Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to copy a tar file on a series of remote hosts and untar it on those hosts?

Am trying to copy a tar file onto a series of remote hosts and untar it at the destination. Need to do this without having to do multiple ssh. Actions to perform within a single ssh session via shell script - copy a file - untar at destination (remote host) OS : Linux RHEL6 (3 Replies)
Discussion started by: sankasu
3 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Deleting Multiple Lines in a File1 using critera found from File 2

Hi Everyone! I would like ask if there's a better way I can delete multiple lines in a file1 by collecting all criteria from file2. file1: a b c d e f file2: a e f The expected value will be: b (3 Replies)
Discussion started by: zzavilz
3 Replies

4. UNIX for Dummies Questions & Answers

Can you specify multiple mailhost's in the /etc/hosts file?

Hello, This question has been posted by another member previously, but no reply/answer was posted to that thread and it has been closed. Searches do not seem to turn up a straight answer as to whether or not this is possible. So I ask the same question: We recently had our SMTP server go... (2 Replies)
Discussion started by: kwasserb
2 Replies

5. UNIX for Dummies Questions & Answers

Can you have multiple mailhost's in the /etc/hosts file?

We recently had an smtp server go down and didn't have a backup. Now that the backup server is up and running, I'd like to set up sendmail on our Solaris 10 servers to failover to the backup mail (smtp) server if the primary refuses connections. I've googled "mailhost" and haven't found... (0 Replies)
Discussion started by: the.gooch
0 Replies

6. Shell Programming and Scripting

pattern matching over multiple lines and deleting the first

I've got a longish log file with content such as Uplink traffic: Downlink traffic: I want to parse the log file and remove any line that contains the string "Uplink traffic:" at the beginning of the line, but only if the line following it beginnings with the string "Downlink traffic:" (in... (7 Replies)
Discussion started by: Yorkie99
7 Replies

7. Shell Programming and Scripting

Deleting multiple lines from file

Hi, I have 10 different strings. I have to delete the whole line matching with any one string. I can use sed like below sed '/$keyword1/d' fileList.txt > temp_fileList.txt sed '/$keyword2/d' temp_fileList.txt > temp_fileList1.txt . . . Here is the problem i do not have fixed number... (9 Replies)
Discussion started by: shekhar_v4
9 Replies

8. Shell Programming and Scripting

deleting lines from multiple text files

I have a directory full of text data files. Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application. I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies

9. UNIX for Advanced & Expert Users

Copy a file to multiple hosts

Hi, I need to copy a file ( say 1MB file ) to multiple hosts( no of machines is huge). What would be the most optimal way of doing it with minimal user intervention ? Thanks, Sumit (5 Replies)
Discussion started by: sumsriva
5 Replies

10. Shell Programming and Scripting

Deleting Multiple Lines with sed

I am trying to use sed to delete multiple lines in a file. The problem is that I need to search for a certain line and then once found delete it plus the next 4 lines. For instance if I had a file that consisted of the following lines: #Data1.start ( (Database= data1) (Name = IPC)... (1 Reply)
Discussion started by: rambo15
1 Replies
Login or Register to Ask a Question