[Linux-disciples] help me write a shell script

Jamie Forrest jamie at honksandsirens.com
Thu Jul 17 11:23:58 EDT 2008


>> 3) Search for all comments in the file, delimited by /* and */ and
>> delete
>
> d) The trick here is that sed(1) works
>   on single lines, whereas /* ... */
>   can span multiple lines. I believe
>   awk(1) can do multiline things, but
>   here I'd just use Perl. Here's a
>   quick-and-dirty way to do it, with
>   disclaimers afterward:
>
>   #!/usr/bin/perl
>   use strict;
>   use warnings;
>   use File::Slurp;
>
>   my $file_contents = read_file('/path/to/filename');
>   $file_contents =~ s#/\*.*?\*/##gsm;
>   print $file_contents;

Is there any way here to modify this to work on stdin rather than a  
file?



More information about the Linux-disciples mailing list