如何解决如何使用sed和grep修复文件
我有一个名字为firstname.lastname的文件,想从姓氏中获取特定数量的字母,然后在文件的每一行后面附加第一个首字母缩写。下面的例子
john.williams需要更改为willij
解决方法
尝试一下:
$ cat test
john.williams
john.doe
jane.doe
lois.lane
$ sed -e 's/\(.\{1\}\).*\.\(.\{1,5\}\).*/\2\1/' test
willij
doej
doej
lanel
$
以下说明:
substitute the following \(.\{1\}\) The very first character,capture it .* Followed by other characters \. Followed by a . \(.\{1,5\}\) Followed by upto 5 characters,capture them .* Followed by other characters with this \2\1 Print the second capture sequence followed by the first sequence
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。