#!/usr/bin/perl -w use strict; use warnings; use utf8; use open qw(:std :utf8); # Skript_texte_zusammen.pl # 2010-08-16 # Wolfgang Schmidle # Nimmt alle Textdateien im Verzeichnis und fügt sie zu einer einzigen Datei zusammen. my $dirname = $ARGV[0]; opendir(DIR, $dirname) or die "Could not open dir $dirname\n"; my @allfiles = readdir DIR; closedir(DIR); my @gesamt; foreach (@allfiles) { if (m!.txt$!) { unless ($_ eq "result.txt") { push @gesamt, "\n\n\n"; open (TEXT, $_) or die "Can't open file $_!\n"; push @gesamt, ; close(TEXT); # my @singlefile = ; # foreach (@singlefile) { # chomp; # push @gesamt, $_ . "\n"; # } } } } foreach (@gesamt) { s!\r!!g; # CRLF --> LF s!^\x{FEFF}+!!; # remove BOM; some text files have two BOMs in the first line! } open (RESULT, ">result.txt"); print RESULT @gesamt; print RESULT "\n"; close (RESULT);