I have a file called message that has the line


I am doing a grep (Platform is AIX 6.1)

grep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 message

it finds the line and displays the output

But, when I try to use wildcard as below

grep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.*/ORDRSP/758 message

it is not finding the line. I have tried with single/double quotes as well. It is not working. Am I missing anything here? I am confused.

closed as off-topic by Jeff Schaller, G-Man, don_crissti, Kusalananda, thrig Mar 21 '17 at 20:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, G-Man, don_crissti, Kusalananda, thrig
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you please post the output of grep 'CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.*/ORDRSP/758' message | sed -n l and of grep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 message | sed -n l ? – Stéphane Chazelas Jun 11 '14 at 14:29
  • @StéphaneChazelas No output displayed for the first command. The second one returns the result line as "RFH $ " – Raj Jun 11 '14 at 14:32
  • 1
    So basically, you're not telling us everything, the line is not CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758? – Stéphane Chazelas Jun 11 '14 at 14:40
  • 1
    If that file contains NUL characters or have lines longer than a few kilobytes, you can't use grep or text utilities, use perl for instance (perl -ne 'print if /regexp/') – Stéphane Chazelas Jun 11 '14 at 14:41
  • 1
    Your original example with the wildcard works successfully for me on AIX 6.1 TL9 SP1, both in ksh and bash the same. Maybe some different grep version? Can you tell me the output of these two commands: which grep and find / -name grep 2>/dev/null ? – Joshua Huber Jun 11 '14 at 17:03

Note: I am unable to test this on AIX, but the following works for me with GNU grep.

grep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.\*/ORDRSP/758 message

or alternatively:

grep 'CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.\+/ORDRSP/758' message

This is because in grep's basic regular expressions, most meta-characters only have their special meaning when escaped. From grep man page:

In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose
their special meaning;  instead  use  the backslashed versions \?, \+, \{,
\|, \(, and \).
  • If grep "CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.*/ORDRSP/758" message didn't work, then grep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/.\*/ORDRSP/758 message won't work either as it's exactly the same command. \+ is a GNUism so will likely not work in AIX. – Stéphane Chazelas Jun 11 '14 at 14:26
  • @StéphaneChazelas Yes, that might work on GNU grep. Its nor working in AIX. I am searching for some other option to work this out – Raj Jun 11 '14 at 14:29
  • AIX grep doesn't have \+. The character * is a wildcard when it is not preceded by a backslash. In …ORDERS05/.\*/ORDRSP/758, the backslash protects the star from shell expansion, so grep sees ORDERS05/.*/ORDRSP/758 and all is well. But that is not working for the OP. – Gilles Jun 11 '14 at 22:39


egrep CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/*/ORDRSP/758 message

Not the answer you're looking for? Browse other questions tagged or ask your own question.