|
|
|
|
|||
|
perlの1つで、複数の入力ファイルをxargsのライナー
最初のリストを1つの列をxargsのパイプへの出力は、実行するためにxargsの指示で6000のファイルを perlの 各ファイルは、 ( )は、 - iオプションとxargsのは、入力ファイルが配置されています。 i.orgのです perlの と、 - pの場合は、 - pの必要があるとは本当に分からないが、元のファイルを保存する perlの スクリプト コード:
ls -1 6000files* | xargs -i perl -i.output -p myscript.pl {} |
|
||||
|
あなたのディレクトリに、これらのテキストファイルでは、内部処理をする必要があると仮定 perlの プログラム: コード:
$ $ cat a.txt This is the first line in file a.txt $ $ cat b.txt This is the first line in file b.txt This is the second line in file b.txt $ $ cat c.txt This is the first line in file c.txt $ $ ここに1つのサンプルプログラムの: コード:
$ $ cat process_files.pl #!perl -w # Script to process all *.txt files in current directory and put the output # in the corresponding *.txt.new files in the current directory again. my $indir = "."; # the input directory name my $outdir = "."; # the output directory name my $i = 0; # loop index my $infile; # the input file name my $outfile; # the output file name while (defined($infile = glob($indir."\\*.txt"))) { # loop through the txt files in directory $indir printf("(%d)\tNow processing file => %s\t",++$i,$infile); $outfile = $outdir."\\".substr($infile,rindex($infile,"\\")+1).".new"; # name the output file open (IFILE, "<$infile") or die "Can't open $infile: $!"; # open input file for reading open (OFILE, ">$outfile") or die "Can't create file: $!"; # create output file for writing while (<IFILE>) { # loop through contents of the input file # now do all your processing here # print to the output file print OFILE "We've processed this line -> ".$_; } close(IFILE) or die "Can't close $infile: $!"; # close input file close(OFILE) or die "Can't close $outfile: $!"; # close output file printf("Output file => %s\n",$outfile); } $ $ 私は、これがWindows上で実行さ+ Cygwin環境からWindowsファイルの区切りを使っています。しずくのようにこのコードでは、入力と出力ディレクトリを設定して、関数、印刷などのドキュメントをチェックする必要がありますが、ここに宣言する必要はないと、または使用すると、以降、我々は現在のディレクトリ内のすべての処理を行っている。 の実行は以下の通りです: コード:
$ $ $ perl process_files.pl (1) Now processing file => .\a.txt Output file => .\a.txt.new (2) Now processing file => .\b.txt Output file => .\b.txt.new (3) Now processing file => .\c.txt Output file => .\c.txt.new $ $ cat a.txt.new We've processed this line -> This is the first line in file a.txt $ $ cat b.txt.new We've processed this line -> This is the first line in file b.txt We've processed this line -> This is the second line in file b.txt $ $ cat c.txt.new We've processed this line -> This is the first line in file c.txt $ $ は、希望に役立ちます tyler_durden |
| スポンサーリンク | ||
|
|
![]() |
| ブックマーク |
| タグ |
| バッチ、 複数のファイルを、 出力 |
| スレッドツール | このスレッドを検索 |
| 表示モード | このスレッド |
|
|
その他のUNIXおよびLinuxフォーラムトピックは参考にすること
|
||||
| スレッド | スレッドスターター | フォーラム | 返信 | 最後の投稿 |
| で複数のファイルの削除はperl | pulkit | シェルプログラミングとスクリプティング | 1 | 2008年2月12日 05:55午前 |
| Perlプログラムを複数のファイルからの読み取り中に | jyotipg | シェルプログラミングとスクリプティング | 1 | 2006年7月19日 10:26午後 |
| 複数の組み合わせを1つでは、 perlスクリプト内のファイル | rahulrathod | シェルプログラミングとスクリプティング | 1 | 2005年12月18日 01:51午前 |
| Perlの-添付ファイルとして複数のファイルをメールで送信 | Tonka52 | シェルプログラミングとスクリプティング | 3 | 2004年2月11日 01:19午後 |
| hファイルに複数のCとの3行を追加するperlの | Lazzar | シェルプログラミングとスクリプティング | 2 | 2003年10月28日 01:30午後 |