0
目前我查找和替换使用如下:如何查找并使用管道传输到sed的文件名列表替换变量?
ack -l oldstring | xargs sed -i '' -e s/oldstring/newstring/g
有没有办法做到这一点,而不必键入出oldstring
不止一次?这就是我试图不工作:
ack -l oldstring | xargs sed -i '' -e s/{}/newstring/g
目前我查找和替换使用如下:如何查找并使用管道传输到sed的文件名列表替换变量?
ack -l oldstring | xargs sed -i '' -e s/oldstring/newstring/g
有没有办法做到这一点,而不必键入出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";
}
这是否帮助? http://stackoverflow.com/questions/14402949/how-to-use-xargs-with-sed-in-search-pattern还是你在一个catch-22? – stevesliva
@stevesliva问题在于这些是针对示例中的一个文件(file.txt)。在我的情况下,ack -l返回一个文件名列表,它们都包含oldstring,我想要应用find和replace命令。 – YPCrumble