sed查找并删除单个单词 [英] Sed find and delete single word

查看:109
本文介绍了sed查找并删除单个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 .htaccess 文件中删除用户名.

I would like to remove a username from a .htaccess file.

示例 .htaccess :

RewriteEngine On
RewriteBase /~usern/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~usern/index.php [L]

我想给我们一种动态命令,因为我不必每次都为每个用户手动键入/〜username .

I want to us a sort of dynamic command in that I don't have to manually type /~username every time for each user.

我尝试过

sed 's/$whoami##g' .htaccess

但这无法达到预期的效果.

but this does not achieve the desired result.

推荐答案

您可以 sed -i"s/$(whoami)//g" .htaccess

如果只想删除一行中的第一个条目,请删除最后一个 g 选项.

If you only want to remove the first entry on a line, remove the last g option.

sed -i(内联sed,直接在文件上执行操作)"s/find_this/replace_with_this/"(搜索并替换)

如果要搜索〜/username并将其删除,而不仅仅是用户名条目,只需将表达式更改为:

If you want to search for ~/username and remove that instead of only username entries, just change the expression to:

sed -i"s/〜\/$(whoami)//g" .htaccess

这篇关于sed查找并删除单个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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