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

说明:

$:行尾标志。

更多sed操作,请参见本博客

sed 简明教程

sed学习实例(一)



你可能感兴趣的:(sed删除行首和行尾空格或者TAB)