申し訳ありませんが、これが冗長な場合ですが、部分的に機能しているperlスクリプトがあります。どちらかを抽出する正規表現foo|bar
と、指定された文字列のプレフィックスがあります。しかし、問題は、私の文字列もファイル名であり、その内容を開いて取得したいことですlocale_col.dat.2010120813.png
(以下の期待される出力を参照)。
出力は次のようになります。
Content:/home/myhome/col/.my_file_del.mail@locale.foo.org
Key1:foo:Key2:col
Content:/home/myhome/col/.my_file_del.dp1.bar.net
Key1:bar:Key2:col
Content:/home/myhome/jab/.my_file_del.mail@locale.foo.org
Key1:foo:Key2:jab
Content:/home/myhome/jab/.my_file_del.dp1.bar.net
Key1:bar:Key2:jab
1回のパスで文字列のリスト(FileList.txtからのファイル名)を読み取り、ファイル名パスから特定の値を抽出し(regexを使用)、その内容のファイル名を開くことができるように、これを微調整するのに助けが必要です。それが理にかなっていることを願っていますか、それともこれを2つのperlスクリプトに分割することを検討していますか?ご入力いただきありがとうございます。
コード(WIP):
open FILE, "< /home/myname/FileList.txt";
while (<FILE>) {
my $line = $_;
chomp($line);
print "Content:$_"; #This is just printing the filenames.
#I want to get the contents of those file names instead. Stuck here.
if ($line =~ m/home\/myname\/(\w{3}).*[.](\w+)[.].*/){
print "Key1:$2:Key2:$1\n";
}
}
close FILE;
FileList.txtの内容:
/home/myname/col/.my_file_del.mail@locale.foo.org
/home/myname/col/.my_file_del.dp1.bar.net
/home/myname/jab/.my_file_del.mail@locale.foo.org
/home/myname/jab/.my_file_del.dp1.bar.net
リストされたファイルの1つのコンテンツの例:(抽出するにはここでヘルプが必要です)
$ cat .my_file_del.mail@locale.foo.org
locale_col.dat.2010120813.png
期待される出力:
Content:locale_col.dat.2010120813.png
Key1:foo:Key2:col
...
..