如何替换每一行中出现的所有字符串? [英] How do I replace all occurences of a string on each line?

查看:73
本文介绍了如何替换每一行中出现的所有字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的脚本中,我想用"+"替换所有出现的用户名",但它仅替换第一次出现的

I want to replace all the occurences of the "username" by, let's say "+" , in the following script but it replaces only the first occurence

ls -al | sed 's/username/+/'

默认情况下,sed的工作方式是什么? 预先感谢.

This is how sed works by default? Thanks in advance.

推荐答案

您需要g(全局)修饰符:

You need the g (global) modifier:

sed 's/username/+/g'

这篇关于如何替换每一行中出现的所有字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆