Go Back   UNIXおよびLinuxフォーラム > トップフォーラム > シェルプログラミングとスクリプティング
Googleのサイト



シェルプログラミングとスクリプティング KSH 、 CSH 、 shに、 bashの、はPerl 、 PHPは、削除するsed 、 Awkの、他のシェルスクリプトやシェルスクリプト言語についての質問の投稿はこちら。

Closed Thread
English Japanese Spanish French German Portuguese Italian を搭載 Powered by Google
 
スレッドツール このスレッドを検索 スレッドを評価 表示モード
  #1固定リンク)  
Old 2009年5月20日
登録ユーザー
 

参加日: 2009年5月
投稿: 2
複数のファイルをperlスクリプト

私は、スクリプトを記述しては、 1つのファイルで動作する時間( ) 。
このように:
$ > perlの myscript.plファイル名>出力

どうすれば> 6000のファイルを実行することができますし、出力が若干変更されたファイル名に送信
$ > perlの myscript 6000files >拡張output6000files.new

見越してありがとう
スポンサーリンク
  #2固定リンク)  
Old 2009年5月20日
durden_tyler's Avatar
登録ユーザー
 

参加日: 2009年4月
投稿数: 664
Bashシェルでは、お客様の現在のディレクトリのすべての入力ファイルは、 " *.テキスト"のパターンに一致すると仮定が含まれて


コード:
for i in *.txt
do
  perl myscript.pl $i > $i.new
done

別の方法としては、プロセスを開いて、内部のファイルを閉じて、 perlの 自身のプログラム。

tyler_durden
  #3固定リンク)  
Old 2009年5月20日
登録ユーザー
 

参加日: 2009年5月
投稿: 3
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 {}

  #4固定リンク)  
Old 2009年5月20日
登録ユーザー
 

参加日: 2009年5月
投稿: 2
素晴らしい!

両方のオプションが私のための仕事をした。ありがとう!
今、もし(おそらく数など)を追加するには、この方法で、私を教育する perlの スクリプトので、私はbashのか、大いに感謝されると、コマンドラインスクリプトを実行する必要はありません。

乾杯

  #5固定リンク)  
Old 2009年5月21日
durden_tyler's Avatar
登録ユーザー
 

参加日: 2009年4月
投稿数: 664
引用:
当初の投稿 aritakum View Post
...この方法を追加する perlの スクリプトので、 bashのコマンドラインまたはスクリプトを実行する必要はありません...
あなたのディレクトリに、これらのテキストファイルでは、内部処理をする必要があると仮定 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
スポンサーリンク
Closed Thread

ブックマーク

タグ
バッチ複数のファイルを出力

スレッドツール このスレッドを検索
このスレッドを検索

高度な検索
表示モード このスレッド
このスレッド

投稿ルール
あなた ことができない。 新しいスレッドを投稿
あなた ことができない。 返信の投稿
あなた ことができない。 添付ファイルの投稿
あなた ことができない。 自分の投稿を編集

BBコード なる 〜の上に
スマイリー なる 〜の上に
[イメージ] コードは 〜の上に
HTMLコードは、 オフ
トラックバック なる 〜の上に
ピングバック なる 〜の上に
Refbacks なる オフ


その他の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午後



すべてGMT -4です。現在の時刻は 02:27午前


提供: vBulletin、著作権© 2000 - 2006、Jelsoft企業株式会社。言語翻訳による電源
vBCredits v1.4著作権© 2007 - 2008 、 PixelFXスタジオ
UNIXおよびLinuxのフォーラムコンテンツの著作権© 1993から2010。すべての権利Reserved.Ad管理で RedTyger

コンテンツ関連のURLで vBSEO 3.2.0