leonardo silva leonardo silva - 3 months ago 12
Bash Question

find + sed not working as expected

I am trying to run a script that searches certain folders for certain files and, if found, replaces an entire line with another sentence. What I tried is below:

#! /bin/sh

I=$(find /home -maxdepth 7 -iname desktop-items-0.conf -exec sed '6s/.*/teste/' {} \;)
echo "$I"

Answer

try this;

#! /bin/sh
I=$(find /home -maxdepth 7 -iname desktop-items-0.conf -exec sed '6s/^.*$/teste/' {} \;)
echo "$I"

ex:

desktop-items-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

after run

line 6 change as below;

[*]
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

If you want to modify file. use sed -i

Comments