使用sed在特定位置插入字符 [英] Insert a character at a specific location using sed

查看:691
本文介绍了使用sed在特定位置插入字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用sed将破折号插入字符串(例如, 201107 2011-07 )?

How to insert a dash into a string using sed (e.g., 201107 to 2011-07)?

推荐答案

echo "201107" | sed 's/201107/2011-07/'

应该可以。但是,只是开个玩笑,这是更通用的解决方案:

Should work. But just kidding, here's the more general solution:

echo "201107" | sed 's/^\(.\{4\}\)/\1-/' 

这将在前四个字符后插入-

This will insert a - after the first four characters.

HTH

这篇关于使用sed在特定位置插入字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆