I need to replace the last occurrence of space in an input file, using sed
.
What I came up with is
sed "s/([ ])[0-9]*$/,/g"
However, it does not seem to want to remember the space which it's supposed to replace. Running the command without round brackets works fine (for what it's supposed to do - replace the space and the chain of numbers). When I add the brackets, it does nothing.
Yes, I am aware of this solution, however when trying to pass \\1
to sed
, it screams that "\\1 not defined in the RE".
Anyone care to help? It seems to be a simple issue, I'd be glad to know the solution.
这似乎“第一次”起作用(是的)......
$ sed -e 's/ \([^ ][^ ]*\)$/,\1/' /etc/hosts
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.