grep on Hex fields


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep on Hex fields
# 1  
Old 06-28-2010
grep on Hex fields

I'm trying to find all modules that contain line feed characters. It shows up at ^M (Hex 0D0A). Does anyone know how to do a search for hex fields?
I tried doing "egrep ^M *.cbl", but that doesn't work.

Thanks!
# 2  
Old 06-28-2010
Try this, type ^M as <Ctrl>-V <Enter>:
Code:
grep '^M' *.cbl

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 06-29-2010
Hex 0D0A is two characters : Carriage Return and Line Feed .
This is the Microsoft MSDOS line terminator for text files.

The unix terminator for text files is just Line Feed (Hex 0A).

If you have text files on your unix box with a Microsoft line terminator they have probably been copied with ftp in binary mode (rather than ascii mode) or come from alien media.

Most unixes come with the "dos2ux" or "dos2unix" conversion program but this can affect foreign character sets.

To just remove Carriage Return characters.
Code:
cat oldfile.txt | tr -d "\r" > newfile.txt

To find the names of your files containing Carriage Return characters.
Code:
#!/bin/ksh
CR=`echo "\0015\c"`
grep -l "${CR}" *.cbl

These 2 Users Gave Thanks to methyl For This Post:
# 4  
Old 06-29-2010
Thanks very much! Both of your suggestions did exactly what I was looking for.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep fields from file

I have two files file1 : USER CURR_TIMES FAIL_CO F_TIME LAST_O_TIME ---------- -------------------------- ------------ ------------------- ------------------- T123 2017-02-25 19:16:58 GMT 3 2017-02-25 13:28:29 2017-02-25 13:42:31 K123 2017-02-25 19:16:58 GMT 3 2017-02-25... (1 Reply)
Discussion started by: jhonnyrip
1 Replies

2. Shell Programming and Scripting

awk to grep rows by multiple fields

Hello, I met a challenge to extract part of the table. I'd like to grep the first three matches based on field1 and field2. Input: D A 92.85 1315 83 11 D A 95.90 757 28 3 D A 94.38 480 20 7 D A 91.21 307 21 6 D A 94.26 244 ... (6 Replies)
Discussion started by: yifangt
6 Replies

3. UNIX for Advanced & Expert Users

Convert 32 bit hex value into fields in decimal

I have 32 bit value in hex that I want to separate into fields and then convert the fields into decimal values. Input file has 2 words of 32 bit hex values: 000001ac ca85210e Output both words separated into individual bit fields: ca85210e: f1(31:9), f2(8:0) f7c392ac: f1(31:14),... (2 Replies)
Discussion started by: morrbie
2 Replies

4. Shell Programming and Scripting

Perl: Parse Hex file into fields

Hi, I want to split/parse certain bits of the hex data into another field. Example: Input data is Word1: 4f72abfd Output: Parse bits (5 to 0) into field word1data1=0x00cd=205 decimal Parse bits (7 to 6) into field word1data2=0x000c=12 decimal etc. Word2: efff3d02 Parse bits (13 to... (1 Reply)
Discussion started by: morrbie
1 Replies

5. Programming

What is the difference between ios::hex and std::hex?

Hi, Is there really a difference between these two, std::hex and ios::hex?? I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true? Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies

6. Shell Programming and Scripting

ignore fields to check in grep

Hi, I have a pipe delimited file. I am checking for junk characters ( non printable characters and unicode values). I am using the following code grep '' file.txt But i want to ignore the name fields. For example field2 is firstname so i want to ignore if the junk characters occur... (4 Replies)
Discussion started by: ashwin3086
4 Replies

7. 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

8. Shell Programming and Scripting

How to grep more than 2 fields?

Hi all, Currently I have this: ps -eo pid,comm| grep CSORDB1T But I need to grep LOCAL=NO as well: ps -eo pid,comm| grep CSORDB1T |grep LOCAL=NO >pdwh_pid However, there's no output. Plz advise how can we grep CSORDB1T & LOCAL=NO at the same time. Thanks! (8 Replies)
Discussion started by: *Jess*
8 Replies

9. Shell Programming and Scripting

How can you grep for three fields

I have data, from which I want to grep for two fields. Only pull out the data if both the fields exist. I have used: egrep --text "field1|field2" file > temp. This seems to be doing an OR. What I am after is an AND. (10 Replies)
Discussion started by: gugs
10 Replies

10. UNIX for Advanced & Expert Users

Grep Line with Matching Fields

Below is the scenario. Help is appreciated. File1: ( 500,000 lines ) : Three fields comma delimited : Not sorted 1234FAA,435612,88975 1224FAB,12345,212356 File2: ( 4,000,000 lines ) : Six fields comma delimited (Last 3 field should match the 3 fields of File1) : Not Sorted : ... (13 Replies)
Discussion started by: hemangjani
13 Replies
Login or Register to Ask a Question