![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help to escape special characters in Korn shell script | rogers42 | UNIX for Dummies Questions & Answers | 6 | 05-14-2009 08:23 AM |
| Escape character | deepakpv | Shell Programming and Scripting | 4 | 02-16-2007 03:19 AM |
| escape characters.. | sharsin2001 | Shell Programming and Scripting | 9 | 11-06-2006 10:52 AM |
| number of escape characters? | Sebarry | Shell Programming and Scripting | 0 | 06-22-2006 05:23 PM |
| lp FormFeed Escape characters | jgordon | UNIX for Advanced & Expert Users | 4 | 10-15-2003 03:01 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Searching for escape characters
Hi all
I have been trying to write a script to look for a set of specific escape characters in a file. On viewing the file via vi it shows this : ^[p^@^E^_^@^@^@^@^@^@^@ Vi also reports at the bottom of the screen [noeol] I understand this means no end of line. I have tried a vary of grep parameters such as grep ^\^. filename grep --binary-file=binary without any luck. I hope someone has a genius idea! ![]() |
|
||||
|
Most versions of awk allow you to represent non-printing characters as hex values. \x01B is ASCII 27, the escape character. Code:
awk '{ if (index($0, "\x01B") ) { print $0 }}' myfile
will find the escape character anywhere on a line in a file, like grep. You will need to construct a whole string of hex chars to find the exact sequence you want. |
|
||||
|
Hi
Thanks to both of you for your replies, I assume these will work in conjunction with checking for the occurrence of the text and return a result value. They both look as though they do. I will try these tomorrow and let you know. ![]() |
|
|||||
|
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 |
|
||||
|
Quote:
SunDude - tried your suggestion, the only draw back to this is that I need to look for more than just the @ sign to make the condition unique. I tried this with the other characters (excluding the [ as grep does not like looking for this character) and still didn't get a result (just got 0). Actually scrap that I think I need to add the backslash to each character so that it is interpreted as a character and not an escape code. I will be back! Last edited by timcs; 05-25-2007 at 04:26 AM.. Reason: Mistake |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|