0

I have a text file, each line is one or more file paths separated with space, all the file has suffix dl, e.g.

/some/path/file.dl
/some/other/path/file2.dl /some/other/path2/file3.dl
/some/other/path3/file4.dl /some/other/path4/file5.dl ...
...

Now I need to transform the above file to another text file. Only the first file of every line should be changed to /out/P{fileName}.h:, {fileName} is the original file name without directory and suffix. e.g.

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

So how can I write the linux shell script?

4

1 回答 1

1

试试这个命令:

$ 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
于 2013-05-15T05:09:52.410 回答