The UNIX and Linux Forums  

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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-24-2007
timcs timcs is offline
Registered User
  
 

Join Date: May 2007
Posts: 6
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!
  #2 (permalink)  
Old 05-24-2007
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
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.
  #3 (permalink)  
Old 05-24-2007
SunDude's Avatar
SunDude SunDude is offline
Registered User
  
 

Join Date: May 2007
Location: New Hampshire
Posts: 3
Is this what you want? : (example binary file was xxd)

root@sundude /usr/local/bin# file xxd
xxd: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, stripped
root@sundude /usr/local/bin# cat -vte xxd > xxd.out
root@sundude /usr/local/bin# grep -c "@" xxd.out
57
root@sundude /usr/local/bin#

NOTE: cat -vte {file_name} will show all characters including carriage returns and such...
NOTE2: Use 'vim' (freeware) and or link vim to vi... vim can handle longer lines and larger pages...

HTH
  #4 (permalink)  
Old 05-24-2007
timcs timcs is offline
Registered User
  
 

Join Date: May 2007
Posts: 6
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.
  #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: 717
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
  #6 (permalink)  
Old 05-25-2007
timcs timcs is offline
Registered User
  
 

Join Date: May 2007
Posts: 6
Drl

Thanks for your input, I haven't yet had chance to try the other suggestions. I think your code could be a little too much though for what I need. Also I don't know if the system I am working with has perl installed.
  #7 (permalink)  
Old 05-25-2007
timcs timcs is offline
Registered User
  
 

Join Date: May 2007
Posts: 6
Quote:
Originally Posted by SunDude
Is this what you want? : (example binary file was xxd)

root@sundude /usr/local/bin# file xxd
xxd: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, stripped
root@sundude /usr/local/bin# cat -vte xxd > xxd.out
root@sundude /usr/local/bin# grep -c "@" xxd.out
57
root@sundude /usr/local/bin#

NOTE: cat -vte {file_name} will show all characters including carriage returns and such...
NOTE2: Use 'vim' (freeware) and or link vim to vi... vim can handle longer lines and larger pages...

HTH

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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0