Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a certain line from a file 2

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
Hi folks,

is it possible to delete a certain line from a file ?

e.G. file containing IP-Adresses:

192.168.2.1 machine1
192.168.2.7 machine2
192.168.3.11 machine3
192.168.3.12 machine4
192.168.7.8 machine5

Now let's say I'd like to delete the following entry without removing the other ones as well:

192.168.3.11 machine3

How can this be done ?

Regards
Thomas
 
Hi

Thomas said:
Now let's say I'd like to delete the following entry without removing the other ones as well
You mean
[ul]
[li]line number 3[/li]
[li]line containing IP address 192.168.3.11[/li]
[li]line containing the IP address of machine3[/li]
[li]line containing the string "192.168.3.11 machine3"[/li]
[/ul]


Feherke.
 
Are you deleting a host from the hosts file?

If you're on AIX use the command [tt]hostent -d IP-Address[/tt]

See man page for hostent

If you want a cross-OS solution, I'm sure Feherke will come up with something.

HTH,

p5wizard
 
Here's one way:

Code:
cp -p /tmp/file /tmp/file.orig &&
egrep -vx '192.168.3.11[[:space:]]+machine3' /tmp/file.orig > /tmp/file

It keeps a backup of the original file, and removes any lines containing only that IP address and machine name, with any number of spaces or tabs in between them.

Annihilannic.
 
Sorry for the late respone.
That's exactly what I was looking for.

Thanks a lot !

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top