[英]how to remove a part of line in text file using linux command
From the line 从行
/mnt/sampleserver/test_1/myfile.pdf
in my text file I want to remove 在我要删除的文本文件中
/mnt/sampleserver/test_1/
Please suggest me how to do it using linux commands. 请建议我如何使用linux命令。
Use the 'basename' command. 使用“基本名称”命令。 Something like this:
basename /mnt/sampleserver/test_1/myfile.pdf
诸如此类:
basename /mnt/sampleserver/test_1/myfile.pdf
You can use any text processing tool, for example, sed: 您可以使用任何文本处理工具,例如sed:
% echo "/mnt/sampleserver/test_1/myfile.pdf" | sed -e 's|/mnt/sampleserver/test_1/||'
myfile.pdf
Several ways: 几种方法:
file="/mnt/sampleserver/test_1/myfile.pdf"
$ echo ${file##*/}
myfile.pdf
$ echo $file | cut -d/ -f5
myfile.pdf
$ echo $file | awk -F/ '{print $5}'
myfile.pdf
Following should get you going. 以下应该可以帮助您前进。 (Note the "\\" for escape character)
(请注意转义字符“ \\”)
/bin/sed -i "s//mnt/sampleserver/test_1///" / bin / sed -i“ s // mnt / sampleserver / test_1 ///”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.