當前位置:首頁 » 編程軟體 » shell腳本xml

shell腳本xml

發布時間: 2023-09-22 18:20:49

linux Shell Sed 命令 -- 如何 處理 XML 文件

1、思路,sed可以刪除指定行內容,也可以在指定行添加內容
2、首先確定BB.Name所在行,如果有重復,需要增加head -1
r1=`grep -n "BB.Name" a.xml|awk -F: '{print $1}'|head -1`
3、<property>行號r2
((r2=r1-1))
4、</property>行號r3
((r3=r1+3))
5、刪除r2和r3中間所有行
sed -i '${r2},${r3}d' a.xml
sed -i '5,8d' a.xml
sed -i '5d' a.xml
6、在r4行處讀入s.txt內容
((r4=r1-2))
sed -i '$r4 r s.txt' a.xml
7、實例
#!/bin/sh
r1=`grep -n "BB.Name" a.xml|awk -F: '{print $1}'|head -1`
((r2=r1-1))
((r3=r1+3))
((r4=r1-2))
sed -i "${r2},${r3}d" a.xml
sed -i "${r4} r s.txt" a.xml

熱點內容
sqldeclarevarchar 發布:2025-05-09 15:15:27 瀏覽:359
演算法是正交 發布:2025-05-09 15:13:06 瀏覽:849
php環境搭建wamp 發布:2025-05-09 15:08:43 瀏覽:910
手機存儲顯示不出來 發布:2025-05-09 15:05:21 瀏覽:924
java字元數組初始化 發布:2025-05-09 15:03:49 瀏覽:106
編譯csharp 發布:2025-05-09 15:03:44 瀏覽:604
CPA經濟資料庫 發布:2025-05-09 15:03:43 瀏覽:348
php加框 發布:2025-05-09 15:03:03 瀏覽:323
c語言獲取cpu 發布:2025-05-09 15:02:52 瀏覽:801
linuxonios 發布:2025-05-09 14:30:23 瀏覽:187