To find and replace values in multiple CSV files without opening Excel, treat them as the plain text they are and run a find and replace across the folder. Anchor the match to the field separators so you change whole values only: for example, find (?<=^|,)NY(?=,|\r?$) with multiline mode on and replace with New York. That changes the field NY but leaves NYC and ANY alone. Working at the text level also avoids the changes Excel makes when it saves a CSV, such as dropping leading zeros and reformatting dates.
This guide covers why Excel is the wrong tool for bulk CSV edits, patterns for whole fields, quoted values and single columns, and how to check the files afterwards.
Why not just use Excel?
Excel's Find and Replace (Ctrl+H) works on one open workbook at a time, so fifty CSV files means fifty open, replace, save cycles. The bigger problem is what happens on save. Excel interprets each value when it opens a CSV, then writes back its interpretation:
| Original value | After opening and saving in Excel | Why |
|---|---|---|
02134 (a ZIP code) | 2134 | Treated as a number |
4111111111111111 | 4.11111E+15 or trailing zeros | Numbers over 15 digits lose precision |
2025-03-04 | 3/4/2025 or 04/03/2025 | Reformatted to your regional date format |
1-2 or MAR1 | A date | Looks like a date to Excel |
| Accented text in UTF-8 | Garbled characters | The file may be opened in the wrong encoding |
A text-level replace changes only the characters you match. Every other byte in the file, including leading zeros, long IDs and dates, stays exactly as it was.
Match whole fields, not parts of fields
A plain search for NY also hits NYC, ANY and SUNY. Whole-word matching helps, but it still matches NY inside a field like NY Office. To change only fields whose entire value is NY, anchor to the separators:
- Find:
(?<=^|,)NY(?=,|\r?$)(multiline mode on) - Replace:
New York
The lookbehind (?<=^|,) means "at the start of a line or right after a comma". The lookahead (?=,|\r?$) means "right before a comma or the end of the line", with the optional \r allowing for Windows line endings. On the line NY,NYC,ANY,NY, only the first and last fields change.
For semicolon-separated files, which Excel produces in many European regional settings, swap the comma for a semicolon: (?<=^|;)NY(?=;|\r?$). For tab-separated files, use \t.
Quoted fields
CSV allows any field to be wrapped in double quotes, and some exports quote every field. To match the value with or without quotes, and keep the quotes as they were:
- Find:
(?<=^|,)("?)NY\1(?=,|\r?$) - Replace:
$1New York$1
The group ("?) captures an opening quote if there is one, and \1 requires the same at the end. The replacement puts the quote back on both sides, so "NY" becomes "New York" and NY becomes New York.
Watch the replacement text itself. If the new value contains a comma, such as New York, NY, it must be quoted or it will split into two fields. If it contains a double quote, CSV requires it to be doubled: "6"" pipe".
Only one column
Sometimes the same value appears in several columns and you only want to change one, for example the third. Skip the first two fields with a counted group:
- Find:
^((?:[^,\r\n]*,){2})NY(?=,|\r?$)(multiline mode on) - Replace:
$1New York
(?:[^,\r\n]*,){2} means "two fields, each followed by a comma". On a,b,NY,NY only the third field changes. Change the 2 to target another column: {0} is the first column, {4} the fifth. This pattern assumes no earlier field contains a quoted comma. If your data has those, use the PowerShell approach below. For more on $1, see capture groups in find and replace.
Column-aware editing with PowerShell
When quoting is irregular, a CSV-aware approach is safer than any regex. PowerShell reads CSV files into objects, one per row:
Import-Csv .\customers.csv | ForEach-Object { if ($_.State -eq 'NY') { $_.State = 'New York' }; $_ } | Export-Csv .\customers-new.csv -NoTypeInformation
This only changes the State column, whatever else is in the row. Be aware of the trade-offs:
- Windows PowerShell 5.1's
Export-Csvputs quotes around every field. PowerShell 7 adds-UseQuotes AsNeededto avoid that. - The output encoding may differ from the input. Add
-Encodingto match. -eqis case-insensitive, so ny also changes. Use-ceqfor an exact match.- For many files, loop over
Get-ChildItem *.csvand write each to a new name, then swap them in after checking.
Several corrections at once
Data clean-ups usually involve a list: state names, product codes, old category names. Rather than one replace per value, put the pairs in a list and apply them all in one pass. Our guide to bulk find and replace from a CSV list explains how to set that up. Order the rules so longer values come before shorter ones that they contain, and use the whole-field pattern for each.
Check the files afterwards
- Count. Search for the old value again with the same whole-field pattern. It should return zero.
- Field counts. A replacement with an unquoted comma adds a column. In PowerShell,
Get-Content f.csv | ForEach-Object { ($_ -split ',').Count } | Sort-Object -Uniquelists the distinct field counts. One number means every line has the same number of fields, assuming no quoted commas. - Import. Load the files into whatever uses them, such as a database import or a script, before deleting the backup.
Doing it across a folder of exports
Bulk Replace treats .csv files as text, so nothing is reinterpreted: leading zeros, long IDs and dates stay as they are. You can stack whole-field regex rules or import a list of corrections from a CSV, preview every change with a before/after diff, and untick any match that should stay. Bulk Replace preserves each file's encoding, which matters for exports that contain accented names, and every run is backed up for one-click undo. Saving the rules as a project also means next month's exports can be corrected the same way in two clicks.
Frequently asked questions
Why not use Excel to replace values in CSV files?
Excel opens one file at a time and can change data on save, such as dropping leading zeros or reformatting dates. A text-level replace leaves everything else as it was.
How do I replace a whole field rather than part of one?
Anchor the match to the separators, for example (?<=^|,)NY(?=,|\r?$) with multiline mode on, so NY is replaced but NYC is not.
What about values inside quotes?
Include the quotes in the search, such as "NY", or write a pattern that allows an optional quote on each side.
