标签:shell
问题:
匹配出关键字sem的行内容,追加到下一个关键字sem前的行首
文本
sem 1234
point 23 33
point 25 aa
point 23 sd
point 19 fd
sem 5412
point 13 tt
point 12 oq
point 12 iw
sem 4513
point 142 iws
point 142 amx
效果
sem 1234 point 23 33
sem 1234 point 25 aa
sem 1234 point 23 sd
sem 1234 point 19 fd
sem 5412 point 13 tt
sem 5412 point 12 oq
sem 5412 point 12 iw
sem 4513 point 142 iws
sem 4513 point 142 amx
解答:
awk ‘!/^sem/{print a,$0}/^sem/{a=$0}‘ file
sem 1234 point 23 33
sem 1234 point 25 aa
sem 1234 point 23 sd
sem 1234 point 19 fd
sem 5412 point 13 tt
sem 5412 point 12 oq
sem 5412 point 12 iw
sem 4513 point 142 iws
sem 4513 point 142 amx
本文出自 “八英里” 博客,请务必保留此出处http://5921271.blog.51cto.com/5911271/1773793
标签:shell
原文地址:http://5921271.blog.51cto.com/5911271/1773793