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
Why do you try to replace newlines? Try this instead:
sed "s/\([^ ]\+\) \+\(.*\)/'\1':'\2'/" input
EDIT -- or with extended regular expressions ( -r
):
sed -r "s/([^ ]+) +(.*)/'\1':'\2'/" input
这是基于注释的awk解决方案:
awk "{print \"'\" \$1 \"':'\" \$2 \"'\"}" input
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.