The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
grep with special characters guruparan18 UNIX Desktop for Dummies Questions & Answers 3 06-12-2008 05:58 AM
Grep with Special Characters Vashj Shell Programming and Scripting 6 11-27-2007 06:51 AM
Grep and extract the characters after thumsup9 UNIX for Dummies Questions & Answers 6 07-04-2007 11:05 AM
quoted-printable content-transfer problems marcpascual UNIX for Advanced & Expert Users 0 03-06-2007 02:56 AM
Best way to search files for non-printable characters? jvander Shell Programming and Scripting 2 03-31-2005 12:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 06-23-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
grep non printable characters

Sometimes obvious things... are not so obvious. I always thought that it was possible to grep non printable characters but not with my GNU grep (5.2.1) version.

Code:
printf "Hello\tWorld" | grep -l '\t'
printf "Hello\tWorld" | grep -l '\x09'
printf "Hello\tWorld" | grep -l '\x{09}'
None of them work. I know that work-arounds with od, cat -vet or sed are possible but why not simply with grep that is meant to do this type of job?

What am I doing wrong?
  #2 (permalink)  
Old 06-23-2008
dearvoid dearvoid is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 4
Try like this:
Code:
$ printf 'hello\tworld' | grep $'\t'
  #3 (permalink)  
Old 06-23-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
With grep you can match control characters like this:

Code:
grep '[[:cntrl:]]'
And non printable characters like this:

Code:
grep '[^[:print:]]'
Another workaround with shells expanding the special construct $'\X' (ksh93, bash, zsh):

Code:
zsh-4.3.4% printf "Hello\tWorld"|grep -l $'\t'
(standard input)
zsh-4.3.4% printf "Hello\tWorld"|grep -l $'\x09'
(standard input)
  #4 (permalink)  
Old 06-23-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Thanks to both it works fine with the $'\x' construct in ksh and bash. Nice to know.
Sponsored Links
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 02:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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