2013-05-15 28 views
0

我有一個文本文件,每一行是一個或空格分隔多個文件路徑,所有的文件具有後綴DL,例如殼牌腳本手柄字符串的sed

/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:{文件名}是沒有目錄和後綴的原始文件名。例如

/out/Pfile.h: 
/out/Pfile2.h: /some/other/path2/file3.dl 
/out/Pfile4.h: /some/other/path2/file5.dl ... 
... 

因此,如何能我寫了Linux shell腳本?

回答

1

試試這個命令:

$ sed -r '[email protected]^\S*/(\S*)\[email protected]/out/P\1.h:@' input 
/out/Pfile.h: 
/out/Pfile2.h: /some/other/path2/file3.dl 
/out/Pfile4.h: /some/other/path4/file5.dl 
+0

謝謝。完全爲我工作。 – Kevin