Title: wp cli search-replace scripting
Last modified: February 7, 2020

---

# wp cli search-replace scripting

 *  Resolved [danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * (@danhgilmore)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-search-replace-scripting/)
 * I have a bash script that runs a search-replace on every table in my WordPress
   installation. It works fine, but I would like to get more specific information
   of the changes.
 * This is part of my bash script:
 *     ```
       SITE_LIST=site_list.csv
       OLDIFS=$IFS
       IFS=,
       while read ID URL UPDATED CREATED
       do
         wp --allow-root --url=$URL search-replace $OLD $NEW
       done < $SITE_LIST
       IFS=$OLDIFS
       ```
   
 * I used the –log option and it worked as expected, but the log was 30MB, and not
   easy to parse the data of what changed.
 * Ideally, I would like to capture the following two bold lines from each wp search
   replace command as it’s run.
 * wp –allow-root –url=$URL search-replace $OLD $NEW wp_1_options
 *     ```
       +--------------+--------------+--------------+------+
       | Table        | Column       | Replacements | Type |
       +--------------+--------------+--------------+------+
       | wp_1_options | option_name  | 0            | SQL  |
       <strong>| wp_1_options | option_value | 1            | PHP  |</strong>
       | wp_1_options | autoload     | 0            | SQL  |
       +--------------+--------------+--------------+------+
       <strong>Success: Made 1 replacement.</strong>
       ```
   
 * Is something like this possible?
    -  This topic was modified 6 years, 2 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Mark Jaquith](https://wordpress.org/support/users/markjaquith/)
 * (@markjaquith)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-search-replace-scripting/#post-12410417)
 * This should get you started:
 * `./your-script.sh | grep -E '(^\\| wp_(\d+_)?options\s+.*\soption_value|Made \
   d+ replacements.)'`
 *  Thread Starter [danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * (@danhgilmore)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-search-replace-scripting/#post-12410628)
 * Thanks! I’ll use your regex and expand it to check for every table (not just 
   options tables).
 *  Thread Starter [danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * (@danhgilmore)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-search-replace-scripting/#post-12411264)
 * Based on Mark’s example, I was able to tweak it to what I needed. This will work
   for every wp_* table in the DB, returning the tables changed or will be changed
   if using dry-run
 * ./test.sh | grep -E ‘(\\|\s[1-9]+|\d+ replace)’
 * This was the return on one site:
 * wp_37_comments comment_author_url 6 SQL
    wp_37_comments comment_content 3 SQL
   wp_37_options option_value 4 PHP Success: 13 replacements to be made.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp cli search-replace scripting’ is closed to new replies.

## Tags

 * [multisite](https://wordpress.org/support/topic-tag/multisite/)
 * [scripting](https://wordpress.org/support/topic-tag/scripting/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/wp-cli-search-replace-scripting/#post-12411264)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
