待處理文字如1-8行文字
$cata 1sed刪除連續指定行:如1-4行2345678
$sedsed刪除不連續指定行:如第一行和第三行'1,4d'a
5678
$sed -e '乙個例子:1d' -e '3d'
a245678
我有乙個list檔案如下:
$cat listtest檔案,test後面的數字對應上面list行號:unknown_other_2 #檔名,我要從檔案裡抓取一些資訊,下同,發現下圖裡沒有有些沒有我想要的資訊,test後面的數字代表這個list檔案的行號
unknown_other_5 #我要刪除大小為0的行
unknown_other_1
f002_other_1
unknown_other_14
t_unknown_other_4
t_unknown_other_6
t_unknown_other_4
t_unknown_other_1
t_unknown_other_4
t_unknown_other_12
t_unknown_other_4
t_unknown_other_13
t_unknown_other_10
t_unknown_other_12
t_unknown_other_4
t_unknown_other_42
t_unknown_other_16
t_unknown_other_27
t_unknown_other_14
t_unknown_other_31
t_unknown_other_12
t_unknown_other_10
t_unknown_other_13
t_unknown_other_11
t_unknown_other_22
t_unknown_other_21
t_unknown_other_45
t_unknown_other_42
t_unknown_other_4
t_unknown_other_33
t_unknown_other_1
t_unknown_other_12
t_unknown_other_14
t_unknown_other_1
t_unknown_other_31
t_unknown_other_4
t_unknown_other_11
t_unknown_other_11
t_unknown_other_3
**如下:
ls -l |awk '}'|cut -d "
t" -f3|xargs -i {} echo -e "
-e {}d
"|xargs|xargs -i {} echo sed -i -e {} list|sh
#執行結果
#sed -i -e test10d -e test12d -e test14d -e test16d -e test2d -e test27d -e test3d -e test31d -e test32d -e test33d -e test35d -e test38d -e test39d -e test4d -e test40d -e test5d -e test9d list
#分解說明
#ls -l |awk '}'
列出大小為0的test檔案
#cut -d "
t" -f3 抓取後面的數字 用字元"t"
分割test檔案,取第三列數字部分
#xargs -i {} echo -e "
-e {}d
"|xargs|xargs -i {} echo sed -i -e {} list 列印執行語句
#sh 執行
sed 刪除某一行 sed刪除指定行
待處理文字如1 8行文字 cata1 sed刪除連續指定行 如1 4行 sed 1,4d a5 sed刪除不連續指定行 如第一行和第三行 sed e 1d e 3d a2 乙個例子 我有乙個list檔案如下 cat list unknown other 2 檔名,我要從檔案裡抓取一些資訊,下同,發現...
sed命令你給刪除指定行
sed命令常用到的兩個選項 i 直接在檔案上編輯 edit files in place e 預設選項 只在命令列輸出,而檔案不改變 add the script to the commands to be executed 注 使用sed命令可以使用 i 或者 e 選項 以下例子僅以 i舉例 se...
linux系統刪除指定的行(sed命令)
1 使用vim建立測試資料 a.txt root linuxprobe test cat a.txt 1w e t 2s f h 3z c g 4e a g 5a f w 6k h d 7 w f r 2 刪除指定的行 root linuxprobe test sed 3d a.txt 刪除第三行 ...