Search code examples
regexsedcshtcsh

Use double quote in grep to match end of line


I am using grep to match file names within Cshell. I would like to match all files which fit $name. without having any other files match such as $name..

When forcing the match to appear at the end of the line by using dollar sign it works good. Only problem is that when i want to use a variable $name i must then use double quotes "" instead of '' and then $ does not work.

> ls back_dir | grep 'aa\.[0-9]$'
aa.1
aa.2

>ls back_dir | grep "aa\.[0-9]$"
Illegal variable name.

Solution

  • You can also mix " and ':

    ls back_dir | grep "aa.[0-9]"'$'
    

    (NB: Works in bash and C-shell.)