LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to search for asterisks using gawk (https://www.linuxquestions.org/questions/linux-general-1/how-to-search-for-asterisks-using-gawk-153901/)

dtheorem 03-05-2004 02:27 PM

How to search for asterisks using gawk
 
I want to use gawk to search for asterisks within a file, call it error.txt
I write:

gawk '/*/' error.txt >> error2.txt

of course it copies everything to error2 because * is a wildcard. However, I would like to search for lines containing a literal asterisk. This must be possible somehow. I prefer not to use sed to change the asterisks.

wapcaplet 03-05-2004 02:35 PM

When searching for special characters like that, it's necessary to 'escape' the character by preceding it with a backslash '\'. That tells gawk (and most other programs which deal with regular expressions) to treat the next character literally. Like so:

gawk '/\*/' error.txt >> error2.txt


All times are GMT -5. The time now is 07:35 AM.