How to show a script without comments?

Joel Roth joelz at pobox.com
Mon Aug 1 19:33:05 UTC 2016


Joel Roth wrote:
> Ralf:

>   test # test                                                                                          
>   test 2                                                                                               
>   echo "Hello #"                                                                                       
>   echo "Hello #" # Oops 
    echo 'Hello #'  

> Hi Ralf,
> 
> This works for double quotes. Removes blank lines.
> 
> cat test.txt | perl -nlE 's/#[^"]*$//g; say unless /^\s*$/'
> 
> This won't work because of shell quoting rules.
>  
> cat test.txt | perl -nlE 's/#[^'"]*$//g; say'

Okay, this does work. Elegant, don't you think?

cat test.txt | perl -nlE 's/#[^'"'"'"]*$//g; say unless /^\s*$/'
 

-- 
Joel Roth
  





More information about the ubuntu-users mailing list