需要帮助将一个sed命令从debian移植到OSX [英] need help porting a sed command from debian to OSX

查看:133
本文介绍了需要帮助将一个sed命令从debian移植到OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个为你sed gurus在那里。我真的不知道sed足以把这完全分开。它写在一些标准的Linux发行版,我需要它运行在OSX上。

This is one for you sed gurus out there. I really don't know enough about sed to take this apart completely. It was written on some standard Linux distro and I need it to run on OSX.

COMPILE_FILES=$(sed -nr '/<script type="text\/javascript"/ { s%^.*src="\{\$baseUrl\}/([^"]+)".*$%\1%p }' templates/common/minifiedScripts.tpl)

第一件事是在OSX版本的sed上不存在r标志,我认为等价的是-E,改变它,但是我得到:

The first thing is that the r flag doesn't exist on the OSX version of sed. I thought the equivalent is -E, so changed it. But then I get:

sed: 1: "/<script type="text\/ja ...": bad flag in substitute command: '}'

谢谢! $ b

推荐答案

OS X sed 不喜欢使用分号或使用大括号(在命令中没有必要)。尝试此操作:

OS X sed doesn't like multiple commands run together using semicolons or grouped in curly braces (which aren't necessary in the command you have). Try this:

COMPILE_FILES=$(sed -n -E '/<script type="text\/javascript"/ s%^.*src="\{\$baseUrl\}/([^"]+)".*$%\1%p' templates/common/minifiedScripts.tpl)

如果您有一个由多个命令组成的 sed 您必须使用 -e

If you have a sed script that consists of multiple commands, you'll have to break them up using -e:

sed -n -E -e '/match/ {' -e 's/foo/bar/' -e 's/baz/qux/' -e 'p' -e '}'

这篇关于需要帮助将一个sed命令从debian移植到OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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