例項:
liujl@liujl-thinkpad-edge-e431:~/mybash/test$ cat seddlt
2、every man』s memory is his private literature. —aldous huxley
4、life is really ******, but we insist on ****** 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'
2、every man』s memory is his private literature. —aldous huxley
4、life is really ******, but we insist on ****** 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'
2、every man』s memory is his private literature. —aldous huxley
4、life is really ******, but we insist on ****** 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操作,請參見本部落格
linux中如何刪除行首和行尾的空格或者製表符
1 測試資料 root desktop 1n42tvh home test ls a.txt root desktop 1n42tvh home test cat a.txt d w g s d s dd d g r d gg d ge root desktop 1n42tvh home test ...
Vim刪除檔案到行首或者行尾
vim用的不是很熟練,只是有時候需要的時候會學習一下 我們知道,vim有三種模式,一種是一般模式,一種是編輯模式,另外一種是命令列模式 在一般模式下,可以進行刪除,複製貼上等操作,在編輯模式下可以編輯檔案,在命令列模式下就是儲存,讀取檔案了 現在我的問題背景是這樣的 我想刪除檔案的某一行到檔案的結尾...
Vim刪除檔案到行首或者行尾
vim用的不是很熟練,只是有時候需要的時候會學習一下 我們知道,vim有三種模式,一種是一般模式,一種是編輯模式,另外一種是命令列模式 在一般模式下,可以進行刪除,複製貼上等操作,在編輯模式下可以編輯檔案,在命令列模式下就是儲存,讀取檔案了 現在我的問題背景是這樣的 我想刪除檔案的某一行到檔案的結尾...