我有一个包含空格的目录列表。
我需要围绕他们',以确保我的批处理脚本会工作。
一个人怎么能围绕一个“和”(引号)每个新行。
如
文件1:
/home/user/some type of file with spaces
/home/user/another type of file with spaces
至
文件2:
'/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'/"
使用SED:
sed -i "s/^.*$/'&'/g" filename
您可以使用SED(1)插入开头,并在文件所以每行尾单引号:
sed -i~ -e "s/^/'/;s/$/'/" the_file
很简单的逻辑,你只需要回声引号前面和后面。
while read -r line
do
echo "'$line'"
# do something
done < "file"