用引号('something')环绕文本文件中的所有行 [英] Surround all lines in a text file with quotes ('something')
本文介绍了用引号('something')环绕文本文件中的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含空格的目录列表。
我需要使用''来包围它们,以确保我的批处理脚本可以正常工作。 >
如何用和(引号)围绕每条新行。
例如
File1:
/ home / user /某些文件类型的空格
/ home / user /另一种类型的空格
File2:
'/ home / user /某些文件类型的空格'
'/ home / user /另一种类型的空格'
解决方案
p>使用sed?
sed -es / \(。* \)/'\1'
或者,如下所述,如果目录可能包含撇号(噩梦,如果他们这样做)使用这个替代
sed -es /'/'\\\\'/ g; s / \\(。* \)/'\1'/
I've got a list of directories that contain spaces.
I need to surround them with ' ' to ensure that my batch scripts will work.
How can one surround each new line with a ' and a ' (quotes).
e.g.
File1:
/home/user/some type of file with spaces
/home/user/another type of file with spaces
To
File2:
'/home/user/some type of file with spaces'
'/home/user/another type of file with spaces'
解决方案
Use sed?
sed -e "s/\(.*\)/'\1'/"
Or, as commented below, if the directories might contain apostrophes (nightmare if they do) use this alternate
sed -e "s/'/'\\\\''/g;s/\(.*\)/'\1'/"
这篇关于用引号('something')环绕文本文件中的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文