简体   繁体   English

在Linux中替换

[英]Replace in Linux

i want to replace string pattern which looks like - 我想替换看起来像的字符串模式-

1234..5678 9876 4567 8245..9745

I want to make this look like - 我想让它看起来像-

{1234..5678} 9876 4567 {8245..9745}

I tried :%s/....\\.\\...../\\{....\\.\\.....\\}/g in vi editor. 我在vi编辑器中尝试了:%s/....\\.\\...../\\{....\\.\\.....\\}/g But its not giving the desired output. 但是它没有给出期望的输出。 Kindly help. 请帮助。

Try this sed : 试试这个sed

sed -i.bak 's#[0-9]\{4\}\.\.[0-9]\{4\}#{&}#g' file.txt

In vim : vim

:%s/[0-9]\{4\}\.\.[0-9]\{4\}/{&}/g

This seems to work: 这似乎可行:

~$ echo 1234..5678 9876 4567 8245..9745 | sed  's/\([0-9]\{4\}\.\.[0-9]\{4\}\)/{\1}/g'
{1234..5678} 9876 4567 {8245..9745}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM