The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 05-24-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 713
Hi.

A perl script:

Code:
#!/usr/bin/perl

# @(#) p1       Demonstrate search for escape.

use warnings;
use strict;

my($lines) = 0;

while ( <> ) {
        $lines++;
        print "$. $_" if /\e/xms;       # always use xms on matches
}

print STDERR " ( Lines read: $lines )\n";

exit(0);

Run on the data file data1, showing special characters:

Code:
% cat -vet data1
Now is the time to see an escape :^[:$
for all good men$
to come to the aid for escape ^[ from jail$
of their country.$

Produces:

Code:
% ./p1 data1
1 Now is the time to see an escape :
3 to come to the aid for escape from jail
 ( Lines read: 4 )

with the line number to help locate the lines ... cheers, drl