使用sed
回答
是否這樣?
ls -l | sed 's/ [0-9].*:.[0-9]//' | less
變換
-rw-r--r-- 1 tomislav tomislav 609 2009-11-26 10:32 Test.class
-rw-r--r-- 1 tomislav tomislav 46 2009-12-14 12:16 test.groovy
到
-rw-r--r-- Test.class
-rw-r--r-- test.groovy
你確定它有效嗎? – ghostdog74 2010-03-16 11:27:15
'g'是不必要的。 – 2010-03-16 11:35:33
對於'ls'打印年份而不是hh:mm的文件,這將失敗。 – hlovdal 2010-03-16 11:38:30
這是一個工作命令。稍微有點棘手的是,ls -l
將打印年份超過一段時間(6個月)的文件,hh:mm
打印新文件。
ls -l | sed 's/ .*[0-9]* .*[A-Z][a-z][a-z] [ 0-9][0-9] \{1,2\}[0-9][0-9]:*[0-9][0-9]//'
對於下面的例子
drwxr-XR-×39根根1024年02月19 8時58分/
起始.*
將匹配39 root root 1024
然後的其餘部分正則表達式與月份名稱相匹配(因此您可能會將az限制爲較少的字符),後跟year或hh:mm。
這不起作用 – ghostdog74 2010-03-16 11:31:50
什麼不起作用?我已經在solaris 10機器上測試並驗證了該命令。 – hlovdal 2010-03-16 11:35:27
ls -l | sed 's/^\([^\t ]\+\)\(.*:.[^ \t]\+\)\(.\+\)/\1 \3/'
waw!爲我工作,謝謝:) – Zenet 2010-03-16 18:38:09
ls -altrh| sed -E 's/ +.+// g'
或者你可以用它支持Perl的正則表達式ssed去。
我使用ssed
程序解決了您的問題,您可以將它安裝在任何Posix系統中,ssed
代表超級sed。 所以我在我的主目錄中做了一個ls -latrh
。
telsa:~ mahmoh$ ls -altrh
total 136
drwxr-xr-x 5 root admin 170B Jun 24 00:27 ../
drwx------+ 4 mahmoh staff 136B Jun 24 00:27 Pictures/
drwx------+ 3 mahmoh staff 102B Jun 24 00:27 Music/
drwx------+ 3 mahmoh staff 102B Jun 24 00:27 Movies/
drwx------+ 3 mahmoh staff 102B Jun 24 00:27 Desktop/
-rw------- 1 mahmoh staff 3B Jun 24 00:27 .CFUserTextEncoding
drwxr-xr-x+ 5 mahmoh staff 170B Jun 24 00:27 Public/
drwx------+ 5 mahmoh staff 170B Jun 24 02:19 Documents/
[email protected] 1 mahmoh staff 15K Jun 24 02:19 .DS_Store
[email protected] 36 mahmoh staff 1.2K Jun 24 14:48 Library/
-rw-r--r-- 1 mahmoh staff 279B Jun 24 15:27 .profile~
[email protected] 1 mahmoh staff 14K Jun 24 15:29 .vimrc
-rw-r--r-- 1 mahmoh staff 279B Jun 24 15:30 .profile
drwx------ 2 mahmoh staff 68B Jun 24 15:46 .Trash/
drwxr-xr-x 3 mahmoh staff 102B Jun 24 20:26 .mplayer/
-rw------- 1 mahmoh staff 3.5K Jun 24 22:11 .bash_history
-rw------- 1 mahmoh staff 42B Jun 24 23:25 .lesshst
-rw-r--r-- 1 mahmoh staff 3.6K Jun 24 23:39 temp
-rw-r--r-- 1 mahmoh staff 3.3K Jun 24 23:43 rtorrent.rc~
drwxr-xr-x 5 mahmoh staff 170B Jun 24 23:52 torrents/
-rw-r--r-- 1 mahmoh staff 3.3K Jun 24 23:56 .rtorrent.rc~
-rw------- 1 mahmoh staff 3.7K Jun 24 23:56 .viminfo
-rw-r--r-- 1 mahmoh staff 3.3K Jun 24 23:56 .rtorrent.rc
drwxr-xr-x+ 25 mahmoh staff 850B Jun 24 23:56 ./
drwx------+ 10 mahmoh staff 340B Jun 24 23:58 Downloads/
現在看。
telsa:~ mahmoh$ ls -altrh| ssed -R -e 's/ +.+//g'
total 136
drwxr-xr-x ../
drwx------+ Pictures/
drwx------+ Music/
drwx------+ Movies/
drwx------+ Desktop/
-rw------- .CFUserTextEncoding
drwxr-xr-x+ Public/
drwx------+ Documents/
[email protected] .DS_Store
[email protected] Library/
-rw-r--r-- .profile~
[email protected] .vimrc
-rw-r--r-- .profile
drwx------ .Trash/
drwxr-xr-x .mplayer/
-rw------- .bash_history
-rw------- .lesshst
-rw-r--r-- temp
-rw-r--r-- rtorrent.rc~
drwxr-xr-x torrents/
-rw-r--r-- .rtorrent.rc~
-rw------- .viminfo
-rw-r--r-- .rtorrent.rc
drwxr-xr-x+ ./
drwx------+ Downloads/
從未聽說過超級sed之前。大起大落。 – the0ther 2014-02-21 19:44:08
爲什麼不使用awk代替sed? awk是爲這樣的東西而構建的。
請參閱this manual page瞭解有關awk中的字段的更多信息。
- 1. 使用SED
- 2. 使用SED
- 3. 使用sed
- 4. 使用SED
- 5. 'sed的' 使用
- 6. 使用sed/awk/
- 7. 使用SED
- 8. 使用SED
- 9. 使用SED
- 10. 使用sed
- 11. URL使用sed
- 12. 使用SED
- 13. 使用sed -e
- 14. 使用SED
- 15. 使用SED
- 16. 使用SED
- 17. 使用SED
- 18. 使用SED
- 19. 使用sed
- 20. 使用sed
- 21. 使用SED
- 22. 使用SED串
- 23. 使用awk,sed
- 24. 多個sed和sed使用管道
- 25. 如何使用SED
- 26. 使用sed命令
- 27. 擦除使用sed
- 28. 如何使用SED
- 29. 移動使用SED
- 30. 如何使用SED
做功課? – ghostdog74 2010-03-16 10:55:48
是的:)和sed是如此強大! – Zenet 2010-03-16 11:00:58
請參閱http://mywiki.wooledge.org/ParsingLs – 2010-03-16 11:35:02