Issue
I need a linux command to grep for a specific IP address inside text files inside the same directory as I am. I would normally use
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file.txt
But I have different text files with different names. So I want to grab just the first possible IP address of all text files inside the same directory as I am rather than using the name of the text file (which is different each time). How would this possible? Maybe with a find
command?
Solution
I suggest with GNU grep:
grep -m 1 -h -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' *
I assume no filename starts with a .
.
See: man grep
Answered By - Cyrus