[英]Error in sed command
input: 输入:
43572154 ROR2
43439911 LOC785925
42737842 LOC785930
expected output 预期产量
'43572154':'ROR2'
'43439911':'LOC785925'
'42737842':'LOC785930'
Commands used 使用的命令
sed s/\n/\'\,\n\'/ input #substitute newline with ',\n'
sed s/ /\'\:\'/ input #substitute <space> with ':'
But there seems to be no effect on the input. 但是似乎对输入没有影响。 Can anyone please point out my error?
谁能指出我的错误? Thnx
n
Why do you try to replace newlines? 为什么您要替换换行符? Try this instead:
尝试以下方法:
sed "s/\([^ ]\+\) \+\(.*\)/'\1':'\2'/" input
EDIT -- or with extended regular expressions ( -r
): 编辑 -或使用扩展的正则表达式(
-r
):
sed -r "s/([^ ]+) +(.*)/'\1':'\2'/" input
这是基于注释的awk解决方案:
awk "{print \"'\" \$1 \"':'\" \$2 \"'\"}" input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.