0

My main directory is

/home/hts/.hts/tvheadend/input/dvb/networks/1d38df81855dee2d39e692ecc4caf05c/muxes 

In there are many more directories with radomly generated names

Example:

/027941cc4936a3a3515c78487abc5445/ /4ab4097f4089f9e6d3c062a96f027707/ /8224af212d24d291570864021d9107a3/ /bffd49d7d6af0f6405b1dba81df70d89/ 

Again in those folders is one file (named "config") and one subfolder (named "services". In the subfolder "services" there are files with a radomly generated name.

Example:

/home/hts/.hts/tvheadend/input/dvb/networks/1d38df81855dee2d39e692ecc4caf05c/muxes/027941cc4936a3a3515c78487abc5445/services/02f1f0807a9228c6543425c4f47312e0 

I want a simple script that enters every single folder under "muxes" and for each of those folders enters the subfolder "services" and replaces the term

"enabled": true, 

through

"enabled": false, 

in every file of that folder.

4
  • 1
    what did you try ?CommentedDec 3, 2016 at 13:43
  • countless versions of find in addition with executing seg command. for example: sudo find . -type f -exec sed -i -e 's/\"enabled\": true,/\"enabled\": false,/g' {} \; which is not enough by far.
    – Daniel
    CommentedDec 3, 2016 at 13:47
  • 1
    this looks good for me what is wrong with it ?CommentedDec 3, 2016 at 14:14
  • well it would change those values in the file "config" as well as in the files of the folder "services". It shouldnt change the "config" file. On top somehow its not recursive.. The command only changes the files while being executed in the same directory. As soon as you execute it in a higher directory it wont change a thing.
    – Daniel
    CommentedDec 4, 2016 at 19:41

1 Answer 1

1

as has been posted in the comments so many options;

#!/bin/bash find /home/hts/.hts/tvheadend/input/dvb/networks/1d38df81855dee2d39e692ecc4caf05c/muxes -maxdepth 1 -type d | while read ad; do find "$ad/config/services/" -type f -exec sed -i 's/"enabled": true,/"enabled": true,/' '{}' \; done 

or

#!/bin/bash dirarr=($(find /home/hts/.hts/tvheadend/input/dvb/networks/1d38df81855dee2d39e692ecc4caf05c/muxes -maxdepth 1 -type d)) for dir in ${dirarr[@]}; do editfile=$(ls -1 $dir/config/services/) sed -i 's/"enabled": true,/"enabled": false,/' $editfile done 
3
  • I'm running the script as root. Rights are set as following: -rwx------ 1 hts video 306 Dez 4 20:44 02f1f0807a9228c6543425c4f47312e0 First example: The script runs fine (no error message) but the values won't change. Second example: I get the error message "sed: can't read 02f1f0807a9228c6543425c4f47312e0: No such file or directory"
    – Daniel
    CommentedDec 4, 2016 at 19:54
  • debug it, use bash -x bash-script.shCommentedDec 4, 2016 at 20:03
  • Changing the first example from: find "$ad/config/services/" -type f -exec sed -i 's/"enabled": true,/"enabled": true,/' '{}' \; to find "$ad/services/" -type f -exec sed -i 's/"enabled": true,/"enabled": false,/' '{}' \; ..works
    – Daniel
    CommentedDec 5, 2016 at 19:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.