我正在尝试运行一个脚本,在某些文件夹中搜索某些文件,如果找到,则用另一个句子替换整行。我试过的是:
#! /bin/sh
I=$(find /home -maxdepth 7 -iname desktop-items-0.conf -exec sed '6s/.*/teste/' {} \;)
echo "$I"
答案 0 :(得分:0)
试试这个;
#! /bin/sh
I=$(find /home -maxdepth 7 -iname desktop-items-0.conf -exec sed '6s/^.*$/teste/' {} \;)
echo "$I"
前:
桌面项-0.conf
[*]
wallpaper_mode=center
wallpaper_common=1
wallpaper=/usr/share/raspberrypi-artwork/raspberry-pi-logo-small.png
desktop_bg=#d6d6d3d3dede
desktop_fg=#000000
desktop_shadow=#d6d6d3d3dede
desktop_font=Roboto Light 12
show_wm_menu=0
sort=mtime;ascending;
show_documents=0
show_trash=1
show_mounts=0
运行后
第6行改变如下;
[*]
wallpaper_mode=center
wallpaper_common=1
wallpaper=/usr/share/raspberrypi-artwork/raspberry-pi-logo-small.png
desktop_bg=#d6d6d3d3dede
teste
desktop_shadow=#d6d6d3d3dede
desktop_font=Roboto Light 12
show_wm_menu=0
sort=mtime;ascending;
show_documents=0
show_trash=1
show_mounts=0
如果要修改文件。使用sed -i