Grep - build character range with octal or hexa representation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep - build character range with octal or hexa representation
# 1  
Old 12-18-2015
Grep - build character range with octal or hexa representation

Hello

I would like to make a character range like that :
Code:
echo "ABCDEF+1234" | grep -E '[\x26-\x40]'

or
Code:
echo "ABCDEF+1234" | grep -E '[\046-\100]'

or
Code:
echo "ABCDEF+1234" | grep -E '[&-@]'

Which should works on linux with english language
And works also on linux with french language ( english install and after add french )
On my second laptop ( french ) I got this error :
Code:
grep: end of interval invalid

but its works on my server (english)
# 2  
Old 12-18-2015
Would this help?
Code:
echo "ABCDEF+1234" | grep -E "[\x26-\x40]"
grep: Invalid range end
echo "ABCDEF+1234" | LC_ALL=C grep -E "[\x26-\x40]"
ABCDEF+1234

---------- Post updated at 17:49 ---------- Previous update was at 17:40 ----------

And this would correctly produce the chars equivalent to the hex codes:
Code:
echo "ABCDEF+1234" | LC_ALL=C grep -E "["$'\x26'-$'\x40'"]"
+ grep -E '[&-@]'
ABCDEF+1234

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-18-2015
Quote:
Originally Posted by RudiC
Would this help?
Code:
echo "ABCDEF+1234" | grep -E "[\x26-\x40]"
grep: Invalid range end
echo "ABCDEF+1234" | LC_ALL=C grep -E "[\x26-\x40]"
ABCDEF+1234

---------- Post updated at 17:49 ---------- Previous update was at 17:40 ----------

And this would correctly produce the chars equivalent to the hex codes:
Code:
echo "ABCDEF+1234" | LC_ALL=C grep -E "["$'\x26'-$'\x40'"]"
+ grep -E '[&-@]'
ABCDEF+1234

Is there a way to put some macro LC_ALL=C at the beginning of the script if language is not English and remove it before the grep pipe
# 4  
Old 12-18-2015
Sorry?
# 5  
Old 12-18-2015
I got it
Put that at the beginning of the script.
Code:
export LC_ALL=C

Valid only for the script

Thank you very much for helping
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Removing letters after a certain character within a range of columns

Hi there, I am trying to remove al letters after : character on specific columns from 10th column till 827. I used sed and cut to do so but I am sure there is better one liner someone can think of from unix community members. Huge file but it has this structure (Total number of Columns =... (10 Replies)
Discussion started by: daashti
10 Replies

2. Shell Programming and Scripting

Replacing character "|" in given character range

Hi I am having file : 1|2443094 |FUNG SIU TO |CLEMENT 2|2443095 |FUNG KIL FO |REMENT This file contains only 3 fields delimeted by "|". Last field is a decsription filed and it contains character "|". Due to this my output if breaking in 4 fields. I... (7 Replies)
Discussion started by: krsnadasa
7 Replies

3. UNIX for Advanced & Expert Users

Finding a specific range of character in file

hi, I want to store from 102 character to 128 character to a variable of header record which can be identified as 'HDR' which is the first 3 characters in the same line of a same.txt file. Please advise. Thanks (4 Replies)
Discussion started by: techmoris
4 Replies

4. Shell Programming and Scripting

Grep ip range

I want to find all files under /var directory that refer to any ip from 10.1.1.1 to 10.1.1.255 using grep. How can this be done. Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies

5. Shell Programming and Scripting

read into a range of character

i have this problem: i must hide a string with a character such as _ by command WORD=string; XXX=`echo $WORD | sed 's//_/g' but after, users must send in input a character and i must to replace the _ with the input character or better i can do this -$CHARS_INPUT i have think to use command... (3 Replies)
Discussion started by: tafazzi87
3 Replies

6. UNIX for Dummies Questions & Answers

Use of character range in awk

Hi all, I am having a bit of a hard time using awk. I must do something wrong, but I don't know what... Any help would be greatly appreciated! I read a file, as follows :... ATOM 21 C THR A 4 23.721 -26.194 1.909 1.00 32.07 C ATOM 22 O THR A 4 ... (2 Replies)
Discussion started by: hypsis
2 Replies

7. Shell Programming and Scripting

grep for a range of numbers

Dear Friends, I want to know how to grep for the lines that has a number between given range(start and end). I have tried the following sed command. sed -n -e '/20030101011442/,/20030101035519/p' However this requires both start and end to be part of the content being grepped. However... (4 Replies)
Discussion started by: tamil.pamaran
4 Replies

8. Shell Programming and Scripting

need help in expanding hexa decimal character range

Hi all, I have a input like this 3AF9:3B01 and need to expand to the below output 3AF9 3AFA 3AFB 3AFC 3AFD 3AFE 3AFF 3B00 3B01 Please let me know the easiest way for achieving this. Thanks for the help in advance... (6 Replies)
Discussion started by: leo.maveriick
6 Replies

9. Shell Programming and Scripting

Need to build a grep/sed/awk filter

Hi I need to to direct only the path and the name of the trace file to a new file. How do I use grep/awk/sed filter? eg. ABC.root>cat alert_omc_dg.log | grep trc ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_3555.trc. ORA-00060: Deadlock detected. More... (8 Replies)
Discussion started by: geetap
8 Replies

10. Shell Programming and Scripting

How to keep(or grep) range of line ?

I have simple text log file look like that ----------------------------------------- Mon May 8 07:02:41 2006 Some text to show log Mon May 8 07:05:30 2006 Some text to show log Some text to show log Mon May 8 07:11:07 2006 Some text to show log Mon May 8 07:45:56 2006 Some text to... (1 Reply)
Discussion started by: aungomarin
1 Replies
Login or Register to Ask a Question