🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: ch.comp.os.linux
Article #22913

Re: replace in datei?

#22913
From: Peter Keel
Date: Wed, 21 Apr 1999 00:00
45 lines
1952 bytes
In article <MPG.11818707c261d910989696@news.unisource.ch>,
	me@ieo.ch (Eggenberger Marc) writes:
> hi ...
> 
> gibt es ein replace in dateien?
> 
> also sowas wie s/muster/neues_muster/g in Perl auf textdateien .. dann 
> msus ichs nicht noch in perl machen (mann bin ich faul ;) ...)

Sowas wie dasda:

#!/usr/bin/perl
#
# Author: Peter Keel <killer@discordia.ch>
# Changes some string in various textfiles into another. Does not accept
# a string on the commandline because I want to be able to use wildcards
# on the filenames.
#

$string1="main.htm";   # or "�" or "none" or whatever..
$string2="index.html"; # or "ss" or "None" or whatever..

die "Usage: $0 filenames\n"       unless($ARGV[0]);

foreach $file_name (@ARGV) {
    $temp_file="/tmp/$file_name";
    open(IN_FILE,"<$file_name") || die "Cannot open $file_name for input\n";
    open(TEMP,">$temp_file");
    while(<IN_FILE>){
        $_ =~ s/$string1/$string2/g;
        print TEMP ($_);
    }
    close IN;
    close TEMP;
    system ("mv $temp_file $file_name");
}


Mehr solchen Krempel gibts auf 
http://killer.discordia.ch/Unix/Programs/

Peter
-- 
"The more prohibitions there are, The poorer the people will be"
-- Lao Tse  
Technical Details
Message-ID: <newscache$1p2jaf$wt9$1@cache.cyberlink.ch>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.11818707c261d910989696@news.unisource.ch>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f4b73,41d145cc5ab75c83
X-Google-Attributes: gidf4b73,public
From: keel@cyberlink.ch (Peter Keel)
Subject: Re: replace in datei?
Date: 1999/04/21
Message-ID: <newscache$1p2jaf$wt9$1@cache.cyberlink.ch>
X-Deja-AN: 469046865
X-NNTP-Posting-Host: fw0.cyberlink.ch
Content-Transfer-Encoding: 8bit
References: <MPG.11818707c261d910989696@news.unisource.ch>
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: usenet@dino.active.ch
X-Trace: dino.active.ch 924678757 29044 193.246.253.11 (21 Apr 1999 07:12:37 GMT)
Organization: Active-Net AG
Mime-Version: 1.0
NNTP-Posting-Date: 21 Apr 1999 07:12:37 GMT
Newsgroups: ch.comp.os.linux