Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Can somebody explain to me what /#&/ is doing in this command? cat /etc/services | sed 's/.*/#&/' > services.tmp
/#&/
cat /etc/services | sed 's/.*/#&/' > services.tmp
该s///构造执行正则表达式替换。搜索零个或多个任意字符.*。替换#之后是匹配的任何文本。效果是输出带有#前缀的每一行。
s///
.*
#
相当于是这样的:
sed 's/^/#/'
以上匹配一行的开头(但不是任何字符)并将其替换为#.
在这两种情况下,所有行(甚至是空行)都匹配。
#它在每一行前面加上一个。