简体   繁体   中英

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. But its not giving the desired output. Kindly help.

Try this sed :

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

In 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}

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.

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