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.
目前我使用以下内容查找和替换:
ack -l oldstring | xargs sed -i '' -e s/oldstring/newstring/g
有没有办法做到这一点而不必oldstring多次输入?这是我正在尝试但不起作用的方法:
oldstring
ack -l oldstring | xargs sed -i '' -e s/{}/newstring/g
我最终决定创建两个 bash 函数来节省输入:
# Function to find and replace. function ags { #!/bin/bash ag -l "$1" | xargs sed -i '' -e "s/$1/$2/g"; } # Function to delete any lines that contain a string. function agd { #!/bin/bash ag -l "$1" | xargs sed -i '' -e "/$1/d"; }