> ## Content Index
> Fetch the complete content index at: https://kudithipudi.org/llms.txt
> Use this file to discover other available public pages before exploring further.

# HOW TO : Use grep to search for credit card numbers
- URL: https://kudithipudi.org/how-to-use-grep-to-search-for-credit-card-numbers/
- Published: 2011-08-18T03:20:05.000Z
- Updated: 2011-08-18T03:20:05.000Z
- Description: I was looking for a quick way to search for credit card numbers in a file and ran across this excellent post by Adrian Rollett. I...
- Author: admin
- Tags: HOWTO, Linux, Technology, Uncategorized, #wp, #wp-post, #Import 2026-08-23 02:32

I was looking for a quick way to search for credit card numbers in a file and ran across [this](http://reluctanthacker.rollett.org/creating-regex-finding-credit-card-numbers-grep?ref=kudithipudi.org) excellent post by [Adrian Rollett](http://twitter.com/?ref=kudithipudi.org#!/acrollet). I tweaked his suggestion a bit to show some additional data.

Original suggestion

```
grep ‘\(^\|[^0-9]\)\{1\}\([345]\{1\}[0-9]\{3\}\|6011\)\{1\}[-]\?[0-9]\{4\}[-]\?\[0-9]\{2\}[-]\?[0-9]\{2\}-\?[0-9]\{1,4\}\($\|[^0-9]\)\{1\}’ FILE_TO_SEARCH
```

My modification

```
grep ‘\([345]\{1\}[0-9]\{3\}\|6011\)\{1\}[ -]\?[0-9]\{4\}[ -]\?[0-9]\{2\}[-]\?[0-9]\{2\}[ -]\?[0-9]\{1,4\}’ –color -H -n FILE_TO_SEARCH
```

The modified command will show the name of the file the number was found and at which line. You can tweak it further using additional options for grep. A good reference guide can be found [here](http://www.computerhope.com/unix/ugrep.htm?ref=kudithipudi.org).