1

I have a directory structure of the following

.
├── dir1
│   ├── a
│   │   ├── x.file
│   │   ├── y.file
│   │   └── z.file
│   ├── b
│   │   ├── x.file
│   │   ├── y.file
│   │   └── z.file
│   └── c
│       ├── x.file
│       ├── y.file
│       └── z.file
└── dir2
    ├── a
    │   ├── x.file
    │   ├── y.file
    │   └── z.file
    ├── b
    │   ├── x.file
    │   ├── y.file
    │   └── z.file
    └── c
        ├── x.file
        ├── y.file
        └── z.file

etc.

There are files named x.file in folders named b that I want to change a phrase in each. How can I do this without changing the other files named x.file in other directories and folders in fastest way possible?

Thank you.

1

Try the following script:

#!/bin/bash

find . -type d -name "b" | while read Folder; do
    find "$Folder" -type f -name "a.xyz" | while read File; do
        sed -i 's/phrase1/phrase2/g' "$File"
    done
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.