出力

出力

mapfile.txt私のLinuxコンピュータには、次の小さなテキストファイル()があります。別のディレクトリとサブディレクトリ内の他のファイルの名前を変更するには、このファイルの情報を使用する必要があります。どうすればいいですか?

質問のヒント:

1.i need to rename the contents of the file .

2. we should match the any of  .config files in the folders and sub folders.The rename should as follows.Column 3 names in the input file should be renamed to column 2 names in the outfile.

3.Yes only the first field should be replaced.

私はこれを試しました:

s/search/replace/g 

しかし、これは正しい形式ではありません。

マップファイル.txt:

PROJECT:DCMS_DEMO:prj1
BLOCK:de_top:blk1
BLOCK:new_block2:blk2
BLOCK:test:blk3
CHECKLIST:Block_DV:checklist1

その他の書類は次のとおりです。

blk3 : 0% : 0%
blk1 : 0.68% : 0.99%
blk2 : 0.00% : 0.00%
OVERALL_STATUS=0.23%
PARTIAL_STATUS=0.33%

期待される:

test : 0% : 0%
de_top : 0.68% : 0.99%
new_block2: 0.00% : 0.00%
OVERALL_STATUS=0.23%
PARTIAL_STATUS=0.33%

ベストアンサー1

そしてawk

awk -F ":" -v OFS=":" 'FNR==NR{a[$3" "]=$2" ";next} $1 in a{ $1=a[$1] };1' mapfile.txt otherfile.txt

出力:

test : 0% : 0%
de_top : 0.68% : 0.99%
new_block2 : 0.00% : 0.00%
OVERALL_STATUS=0.23%
PARTIAL_STATUS=0.33%

おすすめ記事