You can try something like this:

open(INFILE,"/etc/passwd");
@infile = <INFILE>; #don't do this if your file gets big
close INFILE;

foreach(@infile){
  if($_ =~ /^ftp/i){ #if it starts with "ftp"
     $_ = '';        #make it a zero-length string
  }elsif($_ =~ /guest/i){ #else if it contains "guest"
     $_ =~ s/guest/ftp/gi;#replace it with "ftp"
  }
}

open(OUTFILE,">/etc/passwd");
print OUTFILE @infile;

-----Original Message-----
From: Jorge Goncalvez [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 13, 2002 1:41 AM
To: [EMAIL PROTECTED]
Subject: Re:Delete a line and replace


Hi, i have this file /etc/passwd like this:


Everyone:*:0:0:,S-1-1-0::
SYSTEM:*:18:18:,S-1-5-18::
Administrators:*:544:544:,S-1-5-32-544::
Administrator:unused_by_nt/2000/xp:500:513:U-LININF54\Administrator,S-1-5-21
-175
7981266-2139871995-725345543-500:/home/Administrator:/bin/bash
anonymous:unused_by_nt/2000/xp:1017:513:U-LININF54\anonymous,S-1-5-21-175798
1266
-2139871995-725345543-1017:/home/anonymous:/bin/bash
ftp:unused_by_nt/2000/xp:1018:513:U-LININF54\ftp,S-1-5-21-1757981266-2139871
995-
725345543-1018:/:/bin/bash
Guest:unused_by_nt/2000/xp:501:513:U-LININF54\Guest,S-1-5-21-1757981266-2139
8719
95-725345543-501:/home/Guest:/bin/bash
HelpAssistant:unused_by_nt/2000/xp:1000:513:Remote Desktop Help Assistant 
Account,U-LININF54\HelpAssistant,S-1-5-21-1757981266-2139871995-725345543-10
00:/
home/HelpAssistant:/bin/bash


I wanted to delete all the line which begins with ftp and then replace Guest
by 
ftp in all file.

Thanks. 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to