我有一个文本文件,其文件名希望动态添加到每行的末尾。例如,我想要以下内容:

/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-01.wav

/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-02.wav


成为:

/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-01.wav /home/danrothaudiodsp/gfcc_train/ar-01.gfcc

/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-02.wav /home/danrothaudiodsp/gfcc_train/ar-02.gfcc


这需要遍历具有许多行的大型文本文件,如下所示。

我已经有以下awk命令:

awk '{$2="/home/danrothaudiodsp/gfcc_train/" OFS $2} 1' file > newfile


但是我正在寻找要在gfcc_train之后的最后一个'/'之后填写的值。

最佳答案

$ awk '{fname=$0; sub(/.*\//,"",fname); sub(/\.[^.]+$/,"",fname); print $0, "/home/danrothaudiodsp/gfcc_train/" fname ".gfcc"}' file
/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-01.wav /home/danrothaudiodsp/gfcc_train/ar-01.gfcc
/home/danrothaudiodsp/kaldi-trunk/egs/voxforge/s5/voxforge/extracted/1028-20100710-hne/wav/ar-02.wav /home/danrothaudiodsp/gfcc_train/ar-02.gfcc

07-28 08:04