# Searching Through Files - Finding A Particular String And Updating It

<span style="color: rgb(0, 0, 0);">**Main command: <span style="color: rgb(176, 19, 243);">grep -rnw "xA" -e "xB" | xargs sed -i 's/xC/xD/'</span>**</span>

- <span style="color: rgb(0, 0, 0);">**g**</span><span style="color: rgb(0, 0, 0);">**rep** – Obvious, search to find results.</span>
- <span style="color: rgb(0, 0, 0);">**-rnw** – Search all directories after string definition.</span>
- <span style="color: rgb(0, 0, 0);">**“xA”** – Location to search.</span>
- <span style="color: rgb(0, 0, 0);">**“xB”** – String to search. **Has to be in quotations!**</span>
- <span style="color: rgb(0, 0, 0);">**|** - Pipe, put results from grep into sed.</span>
- <span style="color: rgb(0, 0, 0);">**xargs** – Call on argument from result.</span>
- <span style="color: rgb(0, 0, 0);">**sed** – Replace.</span>
- <span style="color: rgb(0, 0, 0);">**'s/xC/xD/'** – Replace string xC with xD.</span>

<span style="color: rgb(0, 0, 0);">If you see on the example below, you would use the grep command up to the pipe symbol first without **-l**, then add it in afterwards. </span><span style="color: rgb(0, 0, 0);">This is used **after** searching for strings. The letter **L** is for grep’ing just the directory location where it finds the result and not actually showing file contents.</span>

<p class="callout warning"><span style="color: rgb(0, 0, 0);">**SED WILL NOT** work if you do not add **-l** into the **-rlnw**. It has to require the absolute paths and not anything else it outputs.</span></p>

<span style="color: rgb(0, 0, 0);">![](https://docs.jasmeow.systems/uploads/images/gallery/2024-02/Z4GEhq4VDVv9YVEA-embedded-image-rtsxtvqx.png)</span>

<span style="text-decoration: underline;"><span style="color: rgb(0, 0, 0); text-decoration: underline;">**An Example**</span></span>

<span style="color: rgb(0, 0, 0);">Searching through LuckPerms configs in all servers to replace connection timeout string.</span>

*<span style="color: rgb(0, 0, 0);">grep -rlnw "connection-timeout: 5000" \*/plugins/LuckPerms | xargs sed -i 's/connection-timeout: 5000/connection-timeout: 20000/'</span>*