本文主要是介绍sed删除行首和行尾空格或者TAB,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实例:
liujl@liujl-ThinkPad-Edge-E431:~/mybash/test$ cat seddlt 1、I am eagerly awaiting my next disappointment. —Ashleigh Brilliant 2、Every man’s memory is his private literature. —Aldous Huxley 3、Life is what happens to you while you’re busy making other plans. —John Lennon 4、Life is really simple, but we insist on making it complicated. —Confucius 5、Do not dwell in the past, do not dream of the future, concentrate the mind on the 6、present moment. —Buddha 7、The more decisions that you are forced to make alone, the more you are aware of 8、your freedom to choose. —Thornton Wilder
1、删除行头空格键和tab键
liujl@liujl-ThinkPad-Edge-E431:~/mybash/test$ cat seddlt | sed 's/^[ \t]*//g'
1、I am eagerly awaiting my next disappointment. —Ashleigh Brilliant
2、Every man’s memory is his private literature. —Aldous Huxley
3、Life is what happens to you while you’re busy making other plans. —John Lennon
4、Life is really simple, but we insist on making it complicated. —Confucius
5、Do not dwell in the past, do not dream of the future, concentrate the mind on the
6、present moment. —Buddha
7、The more decisions that you are forced to make alone, the more you are aware of
8、your freedom to choose. —Thornton Wilder
说明:
1) ^[ \t],是以空格或者tab键开头;与【^】不同,【^】是匹配除【^字符】之外的任意字符,例如5【^12】,匹配50、53、54,但是不匹配51和52
2)*是代表匹配0到多次
2、删除行尾空格和tab
liujl@liujl-ThinkPad-Edge-E431:~/mybash/test$ cat seddlt | sed 's/[ \t]*$//g'1、I am eagerly awaiting my next disappointment. —Ashleigh Brilliant2、Every man’s memory is his private literature. —Aldous Huxley3、Life is what happens to you while you’re busy making other plans. —John Lennon4、Life is really simple, but we insist on making it complicated. —Confucius5、Do not dwell in the past, do not dream of the future, concentrate the mind on the6、present moment. —Buddha7、The more decisions that you are forced to make alone, the more you are aware of8、your freedom to choose. —Thornton Wilder
说明:
$:行尾标志。
更多sed操作,请参见本博客
sed 简明教程
sed学习实例(一)
这篇关于sed删除行首和行尾空格或者TAB的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!