我有一个棘手的问题。
我有这个 .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] 删除。
我来说两句