Converting hex value 7C (for pipe) to CRLF in Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting hex value 7C (for pipe) to CRLF in Unix
# 1  
Old 01-21-2009
Question Converting hex value 7C (for pipe) to CRLF in Unix

I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe).

I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just process as a regular text file in sqr.

The command I am using below replaces EVERY 7 with a ^M and EVERY C with a line feed. What I need, is to replace '7C' with newline or CRLF.

tr '7C' '\r\n' < orig.txt > new.txt

I also tried using sed
sed "s/7C/\n/g" orig.txt > new.txt

but it would only replace 7C with an 'n' and not the line feed that I needed. I have looked at the other threads posted and tried just about all of the suggestions......still no luck so far.

Using tr, can I make the 7C LOOK LIKE 1 character somehow instead of 2? If I could, I would just use the new line (\n) to replace it with.

I would really appreciate your help :-)

Thanks,
Sharon

Last edited by sfedak; 01-21-2009 at 03:52 PM..
# 2  
Old 01-21-2009
Quote:
Originally Posted by sfedak
I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe).

I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just process as a regular text file in sqr.

The command I am using below replaces EVERY 7 with a ^M and EVERY C with a line feed. What I need, is to replace '7C' with newline or CRLF.

tr '7C' '\r\n' < orig.txt > new.txt

tr converts characters, not strings.
Quote:
I also tried using sed
sed "s/7C/\n/g" orig.txt > new.txt

Use single quotes and a literal pipe:

Code:
sed 's/|/\n/g' orig.txt > new.txt

# 3  
Old 01-21-2009
Yes, I was able to use tr or sed with the | and both worked fine - I replaced with \n in both cases................the only problem is, the file comes in with the hex value for the pipe so I need to be able to convert from 7C to line feed.
# 4  
Old 01-21-2009
Quote:
Originally Posted by sfedak
Yes, I was able to use tr or sed with the | and both worked fine - I replaced with \n in both cases................the only problem is, the file comes in with the hex value for the pipe so I need to be able to convert from 7C to line feed.

Code:
sed 's/7C/\n/g'

# 5  
Old 01-21-2009
I actually did try that exact command and for some reason, it will only replace the 7C with n (not line feed)

sed 's/7C/\n/g'


So, I think I'll do this in 2 steps instead of trying to do it in one:

sed 's/7C/|/g'
tr '|' '\n'

thanks for your help :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace CRLF between pipe (|) delimiter with LF

Hi Folks! Need a solution for the following :- Source data ------------- 123|123|<CRLF><CRLF><CRLF>|321<CRLF> Required output ------------------ 123|123|<LF><LF><LF>|321<CRLF> <CRLF> represents carriage return <LF> represents line feed Being hunting high and low for a... (10 Replies)
Discussion started by: hishamzz
10 Replies

2. Shell Programming and Scripting

Converting decimal to hex

How to convert decimal value to hex and than take 1st digits as variable sample data 84844294,5,6 51291736,2,3 84844294,5,6 51291736,2,3 i can use {printf "%x,%d\n",$1,$2} but than i want to filter base on 1st hex digit 1st recrd (1 Reply)
Discussion started by: before4
1 Replies

3. UNIX for Dummies Questions & Answers

Confusion with CRLF (wint) and LF (unix) as end of line seperators

I know that windows uses CRLF as a end of line character while Unix uses LF. But visually i could not see any difference in files while creating on either of plat forms. CR (Carriage Return) means to bring cursor to beginning of line while LF (Line feed) means to bring cursor to next line... (5 Replies)
Discussion started by: sarbjit
5 Replies

4. Shell Programming and Scripting

Converting hex to ascii/decimal

I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal. Data Example: The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the... (16 Replies)
Discussion started by: Shiftkey
16 Replies

5. Shell Programming and Scripting

Converting comma separated to pipe delimited file

Hi, I came across a very good script to convert a comma seperated to pipe delimited file in this forum. the script serves most of the requirement but looks like it does not handle embedded double quotes and commas i.e if the input is like 1234, "value","first,second", "LDC5"monitor",... (15 Replies)
Discussion started by: anijan
15 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. UNIX for Advanced & Expert Users

converting openssl hex dump or PEM format to integer array

Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
Discussion started by: jhopper
1 Replies

8. Programming

how to add CRLF support for CSV file generated in unix

Helo, my server side system is running on a redhat linux o.s. I have c program on the server which export list file into CSV format. now, I want that my program on server side is able to add support for CRLF(carriage return Line feed)into csv file format. so how do i write C program whcih... (3 Replies)
Discussion started by: amitpansuria
3 Replies

9. Shell Programming and Scripting

converting hex to dec

Hi Experts, I have a file called "hex" which contains info like below How do i convert everything in this file to decimal value? Please advice. Thanks (4 Replies)
Discussion started by: aismann
4 Replies

10. Programming

converting hex to ascii

Hi everyone! I was wondering if anyone knows how to change hex code back into ascii. when i process a form: " / " turn to " %2F " " @ " turns to " %40 " " ' " turns to " %27 " " ( " turns to " %28 " " ) " turns to " %29 " this is my code so far: order.txt thanks, primal p.s.... (1 Reply)
Discussion started by: primal
1 Replies
Login or Register to Ask a Question

Featured Tech Videos