我有一个文本文件,每一行是一个或多个用空格分隔的文件路径,所有文件都有后缀dl,例如
/some/path/file.dl
/some/other/path/file2.dl /some/other/path2/file3.dl
/some/other/path3/file4.dl /some/other/path4/file5.dl ...
...
现在我需要将上述文件转换为另一个文本文件。只需要将每行第一个文件改为/out/P{fileName}.h:,{fileName}为原文件名,不带目录和后缀。例如
/out/Pfile.h:
/out/Pfile2.h: /some/other/path2/file3.dl
/out/Pfile4.h: /some/other/path2/file5.dl ...
...
那么如何编写linux shell脚本呢?
最佳答案
试试这个命令:
$ sed -r 's@^\S*/(\S*)\.dl@/out/P\1.h:@' input
/out/Pfile.h:
/out/Pfile2.h: /some/other/path2/file3.dl
/out/Pfile4.h: /some/other/path4/file5.dl
关于linux - 使用 sed 的 Shell 脚本句柄字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16557268/