Sponsored Content
Top Forums Shell Programming and Scripting Grepping for hex characters - explanation? Post 302491099 by DGPickett on Wednesday 26th of January 2011 05:17:22 PM
Old 01-26-2011
My take is the $ is literal, but regex keep morphing under my feet:

Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns

I usually just use the tab key or ctrl-V ctrl-whatever, in ' ', or $(echo a|tr 'a' '\027') (but my tr only does octal). But I use ksh, this is a bash-ism:
Code:
$ bash <<!
echo $'\x61'
!
a
$


Last edited by DGPickett; 01-26-2011 at 06:32 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grepping the first 3 characters from a file

Hi I was wondering if it's possible to use a command to get the first 3 characters of a line in a text file, I tried grep but it returns the whole line but I am only interested in the first 3 characters. Is this possible with grep or I need any other command? Also is it possible deleting from... (2 Replies)
Discussion started by: g-e-n-o
2 Replies

2. UNIX for Dummies Questions & Answers

grepping the first 3 characters from a file

give this a try and let me know if it works grep '^' filename rachael (2 Replies)
Discussion started by: rachael
2 Replies

3. Shell Programming and Scripting

Replacing all but last Hex characters in a text line

I must remove hex characters 0A and 0D from several fields within an MS Access Table. Since I don't think it can be done in Access, I am trying here. I am exporting a Table from Access (must be fixed length fields, I think, for my idea to work here) into a text format. I then want to run a... (2 Replies)
Discussion started by: BAH
2 Replies

4. HP-UX

Hex characters of ascii file

Hi, Whats the command or how do you display the hexadecimal characters of an ascii file. thanks Bud (2 Replies)
Discussion started by: budrito
2 Replies

5. Shell Programming and Scripting

Grepping characters

Hi friends, I want your help. I have a flat file. I want a script to search following pattern in it and once it get that pattern it should grep next 7 characters from it and should keep it in output file output.TXT Pattern is RSTD3R0******* In above example, characters in the place of *... (3 Replies)
Discussion started by: anushree.a
3 Replies

6. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

7. Shell Programming and Scripting

Replacing hex characters '\x0D' with '\x0D\x0A'

Hello All, I have a requirement where I need to replaced the hex character - '\x0D' with 2 hex characters - 'x0D' & 'x0A' I am trying to use SED - But somehow its not working. Any pointers? Also the hex character '\x0D' can occur anywhere in the line. Can this also be accomplished... (6 Replies)
Discussion started by: paragkalra
6 Replies

8. Shell Programming and Scripting

Convert hex values to displayable characters

Hi, I am a bit stuck with displaying characters. I am having values like below in the proper displayable characters. which I would want to print the actual value on the right hand side. I dont want to create an array because I would have to create 255 different values. isnt there another way of... (17 Replies)
Discussion started by: ahmedwaseem2000
17 Replies

9. UNIX for Dummies Questions & Answers

Replacing hex characters

I have the following file consisting of dates and sample measurements: 05��Oct��2010 1.31�� 06��Oct��2010 1.32�� 07��Oct��2010 1.31�� The hex characters are \xc2\xa0 in sequence. I have tried to remove the characters as follows: sed -i '' -e 's/\xc2\xa0//g' file.dat and as follows... (6 Replies)
Discussion started by: figaro
6 Replies

10. HP-UX

Replacing Hex Characters In A File Using awk?

Hi guys, First off, i'm a complete noob to UNIX and LINUX so apologies if I don't understand the basics! I have a file which contains a hex value of '0D' at the end of each line when I look at it in a hex viewer. I need to change it so it contains a hex value of '0D0A0A' I thought... (10 Replies)
Discussion started by: AndyBSG
10 Replies
Regexp::Optimizer(3pm)					User Contributed Perl Documentation				    Regexp::Optimizer(3pm)

NAME
Regexp::Optimizer - optimizes regular expressions SYNOPSIS
use Regexp::Optimizer; my $o = Regexp::Optimizer->new; my $re = $o->optimize(qr/foobar|fooxar|foozap/); # $re is now qr/foo(?:[bx]ar|zap)/ ABSTRACT
This module does, ahem, attempts to, optimize regular expressions. INSTALLATION
To install this module type the following: perl Makefile.PL make make test make install DESCRIPTION
Here is a quote from perltodo. Factoring out common suffices/prefices in regexps (trie optimization) Currently, the user has to optimize "foo|far" and "foo|goo" into "f(?:oo|ar)" and "[fg]oo" by hand; this could be done automatically. This module implements just that. EXPORT Since this is an OO module there is no symbol exported. METHODS
This module is implemented as a subclass of Regexp::List. For methods not listed here, see Regexp::List. $o = Regexp::Optimizer->new; $o->set(key => value, ...) Just the same us Regexp::List except for the attribute below; unexpand When set to one, $o->optimize() tries to $o->expand before actually starting the operation. # cases you need to set expand => 1 $o->set(expand => 1)->optimize(qr/ foobar| fooxar| foozar /x); $re = $o->optimize(regexp); Does the job. Note that unlike "->list2re()" in Regexp::List, the argument is the regular expression itself. What it basically does is to find groups will alterations and replace it with the result of "$o->list2re". $re = $o->list2re(list of words ...) Same as "list2re()" in Regexp::List in terms of functionality but how it tokenize "atoms" is different since the arguments can be regular expressions, not just strings. Here is a brief example. my @expr = qw/foobar fooba+/; Regexp::List->new->list2re(@expr) eq qr/fooba[+r]/; Regexp::Optimizer->new->list2re(@expr) eq qr/foob(?:a+ar)/; CAVEATS
This module is still experimental. Do not assume that the result is the same as the unoptimized version. o When you just want a regular expression which matches normal words with not metacharacters, use <Regexp::List>. It's more robus and much faster. o When you have a list of regular expessions which you want to aggregate, use "list2re" of THIS MODULE. o Use "->optimize()" when and only when you already have a big regular expression with alterations therein. "->optimize()" does support nested groups but its parser is not tested very well. BUGS
o Regex parser in this module (which itself is implemented by regular expression) is not as thoroughly tested as Regexp::List o May still fall into deep recursion when you attempt to optimize deeply nested regexp. See "PRACTICALITY". o Does not grok (?{expression}) and (?(cond)yes|no) constructs yet o You need to escape characters in character classes. $o->optimize(qr/[a-z()]|[A-Z]/); # wrong $o->optimize(qr/[a-z()]|[A-Z]/); # right $o->optimize(qr/[0-9A-Za-z]|[Q-_.!~*"'()E]/ # right, too. o When character(?: class(?:es)?)? are aggregated, duplicate ranges are left as is. Though functionally OK, it is cosmetically ugly. $o->optimize(qr/[0-5]|[5-9]|0123456789/); # simply turns into [0-5][5-9]0123456789] not [0-9] I left it that way because marking-rearranging approach can result a humongous result when unicode characters are concerned (and p{Properties}). PRACTICALITY
Though this module is still experimental, It is still good enough even for such deeply nested regexes as the followng. # See 3.2.2 of http://www.ietf.org/rfc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9A-Fa-f])|[:@&=+$,]))*)*(?:/(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*(?:;(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*)*)*(?:\?(?:(?:[;/?:@&=+$,a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f]))*)?)? By carefully examine both you can find that character classes are properly aggregated. SEE ALSO
Regexp::List -- upon which this module is based "eg/" directory in this package contains example scripts. Perl standard documents L<perltodo>, L<perlre> CPAN Modules Regexp::Presuf, Text::Trie Books Mastering Regular Expressions <http://www.oreilly.com/catalog/regex2/> AUTHOR
Dan Kogai <dankogai@dan.co.jp> COPYRIGHT AND LICENSE
Copyright 2003 by Dan Kogai This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2004-12-05 Regexp::Optimizer(3pm)
All times are GMT -4. The time now is 04:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy