I have a text file that contains full path of some files. for example,
/one/file.name
/this/is/another/filename
/and/one/more/file.here
I want to convert this file in the following format:
/one/file.name ./file.name
/this/is/another/filename ./filename
/and/one/more/file.here ./file.here
That is, extract only the name of the file and append it to the same line, along with ./ before it
I thought of using sed, but can't get the correct regex. anobody can solve this problem?
alternative in Python:
import os,fileinput
for lines in fileinput.FileInput("input.txt",inplace=1) : #inplace edit
lines = lines.strip() #strip newlines
filename = os.path.split(lines)[-1]
print lines ,"./%s" %filename #write to file in place
output:
/one/file.name ./file.name
/this/is/another/filename ./filename
/and/one/more/file.here ./file.here
aigles
3
Try this:
sed 's_/[^/]*$_& .&_' filename
Jean-Pierre.
thanks much Jean-Pierre, that works very well!
anbu23
5
while read str
do
echo $str" ./"${str##/*/}
done < file