sed、grep 和 awk 文件排序

sed、grep 和 awk 文件排序

我試圖從目錄中獲取名稱中包含“load”的所有檔案。我正在嘗試做:

find -type f | sed -s 'load

但是,我經常收到錯誤

sed:-e 表達式 #1,字元 1:未知指令:`f'

更糟的是,雖然我能夠操作正規表示式,但我真的不擅長使用 grep/sed/awk,這一直在減慢我的速度。到目前為止我在網上找到的任何材料都不是很好。你們知道任何全面且相當簡潔的截圖影片/教學嗎?我仍然懷念閱讀和快速理解 Linux 手冊的能力。

答案1

您根本不需要 grep/sed/awk,讓我們find為您過濾結果:

find . -type f -name '*load*'

或者,僅在 bash 中

shopt -s globstar nullglob
load_files=( **/*load* )

如果您確實需要外部工具:

find . -type f | grep load
find . -type f | awk '/load/'
find . -type f | sed -n '/load/p'

對於 sed,使用 -n 抑制正常輸出,並且僅列印與模式相符的行。

相關內容