0
所以,我試圖刪除表格中的數字後,我從命令行格式化的選項卡。以下是原始表中的數據,有關從文件coipied和直接粘貼:奇怪的行爲,使用`sed`
File Path Line Description
/home/nick/.bashrc 9 # TODO Chop this into code import files
/home/nick/.bashrc 204 # TODO Add $HOME/os-setup to OS installation disc
/home/nick/.bashrc 207 # TODO Custom power actions don't work; system tray notifications
當添加一個最終sed
命令,但是管,出現一些奇怪的行爲。作爲一個例子,考慮下面的sed
命令:
cat somefile.txt | column -tx -s : | sed -e 's/\([0-9]\{1,\}\)/\1/g'
File Path Line Description
/home/nick/.bashrc 9 # TODO Chop this into code import files
/home/nick/.bashrc 204 # TODO Add $HOME/os-setup to OS installation disc
/home/nick/.bashrc 207 # TODO Custom power actions don't work; system tray notifications
此查找表中的每一行中的數字,然後替換匹配正則表達式的第一部分。由於整個比賽用大括號包裹,這意味着沒有任何變化,因爲它被替換爲自身。
然而,當我再試試同一sed
命令,但我添加了\t
字符,文字標籤,以匹配正則表達式的sed
輸出似乎也截斷號碼匹配!見下:
cat somefile.txt | column -tx -s : | sed -e 's/\([0-9]\{1,\}\)\t/\1/g'
File Path Line Description
/home/nick/.bashrc # TODO Chop this into code import files
/home/nick/.bashrc 20 # TODO Add $HOME/os-setup to OS installation disc
/home/nick/.bashrc 20 # TODO Custom power actions don't work; system tray notifications
爲什麼sed
截斷每個數字的最後一位數字?如何停止sed
這樣做?
可以請你用\ t顯示sed代碼嗎? –
有趣,不能重現 –
@NickBull:這個文件從哪裏來的? – sjsam