首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何运行GnuWin32 sed和脚本文件?

如何运行GnuWin32 sed和脚本文件?
EN

Stack Overflow用户
提问于 2019-03-01 15:09:55
回答 1查看 108关注 0票数 2

我在Windows 10下运行Windows 10

我试图使用Gnu Bash运行以下sed一行:

代码语言:javascript
复制
sed -f <(sed -E 's_(.+)\t(.+)_s/\1/\2/g_' C:/dictionary.txt) C:/content.txt

file substitute sed语句将字典项转换为sed表达式。main sed将它们用于内容替换。

这是用How to awk to read a dictionary and replace words in a file?描述的

dictionary.txt看起来是这样的:

代码语言:javascript
复制
aluminium<tab>aluminum
analyse<tab>analyze
white spirit<tab>mineral spirits
stag night<tab>bachelor party
savoury<tab>savory
potato crisp<tab>potato chip
mashed potato<tab>mashed potatoes

content.txt看起来是这样的:

代码语言:javascript
复制
The container of white spirit was made of aluminium.
We will use an aromatic method to analyse properties of white spirit.
No one drank white spirit at stag night.
Many people think that a potato crisp is savoury, but some would rather eat mashed potato.
...
more sentences

在windows 10下在GnuBash中运行GnuWin32 32/sed时,我收到以下错误消息:syntax error near unexpected token <(s

如何重新制定在windows 10?下GnuWin32 32/sed下运行的脚本

感谢https://stackoverflow.com/users/2836621/mark-setchellhttps://stackoverflow.com/users/5403468/tiw,该解决方案在使用cygwin64时起作用

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-01 16:09:31

一种方法是先将内部sed输出写入临时文件,然后使用它,然后删除它:

代码语言:javascript
复制
sed -r "s_(.+)\t(.+)_s/\1/\2/g_" C:/dictionary.txt>tmp_script.sed
sed -f tmp_script.sed C:/content.txt
del tmp_script.sed

另一种方式是,根据马克·塞切尔的评论,加上一些小改动,cygwin 安装了

这个工作既适用于bash,也适用于批处理:

代码语言:javascript
复制
sed -r "s_(.+)\t(.+)_s/\1/\2/g_" C:/dictionary.txt | sed -f /dev/stdin C:/content.txt
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54947345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档