脚本中 SED-POSIX 指定的 -E 选项

何塞·安东尼奥·彼德耶罗·阿里亚斯

我有一个棘手的问题。

我有这个 .sed 脚本,我需要在其中做一些事情,然后使用“ sed -f script.sed filename.csv ”执行脚本的所有行

在脚本内部,我使用了正则表达式,如果在执行脚本时我使用-E,则脚本可以工作。(sed -E -f script.sed 文件名.csv)

但是,问题是,我不能使用它,所以在终端中我需要像这样执行脚本“ sed -f script.sed filename.csv

然后,问题是,是否有一种人类可能的方法来使正则表达式在 SCRIPT 中工作而不在终端中使用 -E?它可以以某种方式包含在脚本中吗?

我将写下脚本以提供更多上下文:

s/ESP/Spain/g  #this line changes ESP for Spain in all rows

s/DEN/Denmark/g  #this line changes DEN for Denmark in all rows

s/NED/Netherlands/g  #this line changes NED for Netherlands in all rows

s/^([^,]*,)([^,]+)((,[^,]*){5},(shooting|judo),)/\1\U\2\L\3/  #This line, changes to UPPER CASE all names of athletes that have as sport either judo or shooting. This is the line that does not work without the -E in the terminal.

/[0],[0],[0],$/d  #This line deletes all rows where the last 3 columns have these values

1 c id,name,nationality,sex,date_of_birth,height,weight,sport,gold,silver,bronze,info   #this line makes the header not upper case 

如果你需要一些数据来处理,你有它:

id,name,nationality,sex,date_of_birth,height,weight,sport,gold,silver,bronze,info
388896171,Abdelraouf Benguit,ALG,male,1985-07-03,1.83,90,judo,0,0,0,
285603057,Abderrahmane Mansouri,ALG,male,1995-01-13,1.72,66,cycling,0,0,0,
545134894,Abderrahmane Meziane,ALG,male,1994-03-07,1.68,62,football,0,0,0,
969824503,Abdullah Alrashidi,IOA,male,1963-08-21,1.83,84,shooting,0,0,1,
897549624,Abdullah Hel Baki,BAN,male,1989-08-01,,,shooting,0,0,0,
153457,Abdullahi Shehu,NGR,male,1993-03-12,1.70,,football,0,0,1,

这是名为运动员v2.csv 的文件的一部分

请不要问为什么我不能使用它,但是我被禁止使用这个选项。

BR,

维克托·斯特里比泽夫

您可以按原样使用前三个命令:

s/ESP/Spain/g  #this line changes ESP for Spain in all rows
s/DEN/Denmark/g  #this line changes DEN for Denmark in all rows
s/NED/Netherlands/g  #this line changes NED for Netherlands in all rows

第四个命令应“转换”为 POSIX BRE:

s/^\([^,]*,\)\([^,]\+\)\(\(,[^,]*\)\{5\},\(shooting\|judo\),\)/\1\U\2\L\3/

请注意,此语法仅受 GNU 支持sed\|作为交替运算符和\+作为一个或多个量词是 GNU 扩展)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Spring Data MongoDB中返回Stream时指定游标选项?

在bash脚本中将sed未知选项设置为s

在POSIX shell中是否需要使用command -v选项?posh符合POSIX吗?

Magento 1.9.2中的“请指定产品的选项”

在Apache Beam中为BigQueryIO指定架构更新选项

sed:-e表达式#1,字符10:Windows上git中s的未知选项

使用sed和env变量在bash脚本中的选项卡上的特定行插入新行

sed:替换表达式中的错误选项:替换表达式中的错误选项

使用SED在文件指定的行中将行插入文件中

用sed中的单个选项卡替换选项卡

sed中的-n选项有什么作用?

bash中set -o选项的预期有效顺序是什么?“ histexpand”胜过“ posix”吗?

netcat中的无效选项-e

为什么POSIX Shell脚本中的这些嵌套选项是单词拆分的?

Android busybox sed:替换表达式中的错误选项

sed中的-e选项有什么作用?

Sed:`s'的未知选项

为什么我无法在sed中找到选项“ -E”

在exec命令中通过变量指定重定向选项

POSIX Shell语法中“未指定是ASSIGNMENT_WORD还是WORD”规则的含义是什么

命令grep中的-e选项

将-e选项与sed一起使用以从脚本运行sed失败

用POSIX sed连接线

如何从 OptionParser 中获取指定的选项标志

指定 rootfs 挂载选项

如何在 sed -e 命令中组合多个选项?

sed :sed 脚本中“s”的未知选项

在 sed 命令中使用变量 - sed -e 异常:`s' 的未知选项

是否可以在 sed 中同时使用选项 -i 和 -E?