grep using ASCII values


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep using ASCII values
# 1  
Old 01-09-2008
grep using ASCII values

machine: HPUX

file: a.dat

contents:
decimal 1
decimal 2
string 1
string 2

ASCII value of 'd': 100.

to grep lines that have 'd', I use the following command
grep d a.dat

My requirement:
I should grep for lines that contain 'd'. But I should use ASCII value of 'd' in the command line.

I played around with 'grep \100' etc. But could not get the expected result. Please help me out in this.

Thanks,
sriksama
# 2  
Old 01-09-2008
Code:
#!/bin/sh
awk -v c="$1" 'BEGIN{input=sprintf ("%c", c)}$0~input' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies

2. Shell Programming and Scripting

Replace alphabets in a string with their ASCII values

hi. I have a requirement where I need to REPLACE all alphabets from an alphanumeric input string into their respective ASCII decimal value. For example: If the input string is ABAC123, the output should be 65666567123 I am seeking a single line command, and I was trying searching for options... (21 Replies)
Discussion started by: kumarjt
21 Replies

3. UNIX for Beginners Questions & Answers

Convert ascii character values to number that comes between the numbers in UNIX

I have variable that contains multiple values of number and also include overpunch(i.e. # $ % etc) character so we want to replace it with numbers. here are the example: Code: 11500#.0# 28575$.5$ 527#.7# 42".2" 2794 .4 2279!.9! 1067&.7& 926#.6# 2279!.9! 885".5" 11714$.4$ 27361'.1'... (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies

4. Shell Programming and Scripting

Anagram finder based in Ascii values

Hello, i need some help with a programm i want to make, what i want to do is to make a dictionary and include some anagrams with it, and make the programm read the Ascii value of each word, and compare them with the anagrams and make the programm print the words that have the same Ascii value,... (1 Reply)
Discussion started by: jose2802
1 Replies

5. Shell Programming and Scripting

Grep to remove non-ASCII characters

I have been having an encoding problem that I need to solve. I have an 4-column tab-separated file: I need to remove all of the lines that contain the string 'vis-а-vis' achiever-n vis-а-vis+ns-j+vp oppose-v 1 achiever-n vis-а-vis+ns-the+vg assess-v 1 administrator-n ... (4 Replies)
Discussion started by: owwow14
4 Replies

6. UNIX for Dummies Questions & Answers

How to grep for a non-standard ASCII character?

A very simple question but I have scoured the web and can't find an answer. How do I search for a character by ASCII code in a regular expression using grep? For example, we use the End of Medium symbol as a delimiter in certain files. (this is ascii 031 in oct, displays as ^Y) I want to grep... (6 Replies)
Discussion started by: DJR
6 Replies

7. Shell Programming and Scripting

Incrementing ascii values

Hi All, I require some help with the below: I am trying to incriment the ascii value of a letter and then print it. So basically "a" becomes "b" and "z" becomes "A". Does anyone have any pointers? Cheers, Parks (10 Replies)
Discussion started by: bParks
10 Replies

8. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

9. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

10. UNIX for Dummies Questions & Answers

Non-ascii character detection (perl or grep)

Hi, Can I know how to grep for lines with non-ascii characters in a file? If not grep, at least can we do it with command-line perl or awk? I tried the functionality of perl, but still could not get the result. Any help?? PS: I was sure that someone should have asked this question... (9 Replies)
Discussion started by: srinivasan_85
9 Replies
Login or Register to Ask a Question