使用sed在bash中查找和替换循环 [英] using sed to find and replace in bash for loop

查看:243
本文介绍了使用sed在bash中查找和替换循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文本文件中要替换的单词很多.

I have a large number of words in a text file to replace.

这个脚本一直运行到我得到sed命令为止:

This script is working up until the sed command where I get:

sed:1:"*.js":无效的命令代码*

sed: 1: "*.js": invalid command code *

PS ... Bash不是我的强项之一-不需要漂亮或有效

PS... Bash isn't one of my strong points - this doesn't need to be pretty or efficient

cd '/Users/xxxxxx/Sites/xxxxxx'
    echo `pwd`;

    for line in `cat myFile.txt`
    do
        export IFS=":"
        i=0
        list=()

        for word in $line; do
            list[$i]=$word
            i=$[i+1]
        done

        echo ${list[0]}
        echo ${list[1]}

        sed -i "s/{$list[0]}/{$list[1]}/g" *.js

    done

推荐答案

您正在运行BSD sed(在OS X下),因此-i标志需要一个参数来指定您希望后缀为什么.

You're running BSD sed (under OS X), therefore the -i flag requires an argument specifying what you want the suffix to be.

此外,没有文件与全局*.js匹配.

Also, no files match the glob *.js.

这篇关于使用sed在bash中查找和替换循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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