LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Grep for "ab?c12345678" From a file (https://www.linuxquestions.org/questions/linux-newbie-8/grep-for-ab-c12345678-from-a-file-879297/)

Fracker 05-07-2011 12:29 AM

Grep for "ab?c12345678" From a file
 
Hello,

How to grep a string like "ab?c12345678" where 3rd character is unknown, while other characters are known.

grail 05-07-2011 01:24 AM

Stick a dot in there instead, unless by using the question mark you are saying that it may or may not be there?
Code:

ab.c12345678
ab.?c12345678

These are different. I will leave you to find out what the difference is :)

penguiniator 05-07-2011 01:24 AM

Type "man grep" at a terminal and then "/REGULAR EXPRESSIONS":

"The period . matches any single character."

So: grep 'ab.c12345678' file

will search file for lines containing the above string with any character in the third position.

And: echo $string | grep 'ab.c12345678'

will search $string for the same pattern.


All times are GMT -5. The time now is 10:33 AM.