Losing carriage return (X0D) after running awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Losing carriage return (X0D) after running awk command
# 1  
Old 06-07-2016
Losing carriage return (X0D) after running awk command

Hi Forum.

I'm running the following awk command to extract the suffix value (pos 38) from the "AM00" record and append to the end of the "AM01" record.

Code:
awk 'substr($0,13,4)=="AM00" {SUFFIX = substr($0,38,2)} substr($0,13,4)=="AM01" {$0 = $0 SUFFIX} 1'  before.txt > after.txt

Code:
Before.txt:
000000000001AM00 1500895700000000000187                                  
000000000001AM01 035000000000013000399820810000000

AM01 record - In hex value:
.....20 20 20 20 20 20 0D 0A

After.txt:
000000000001AM00 1500895700000000000187                                  
000000000001AM01 03500000000001300039982081000000087

AM01 record - In hex value:
.....20 20 20 20 20 20 38 37 0A

It seems or appears that the Hexadecimal 0D was removed after running the awk command.

Any way to resolve this?

Thanks.




Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 06-07-2016 at 02:52 PM.. Reason: Added code tags.
# 2  
Old 06-07-2016
Are you sure the hex dump is from the same file? It should read . . . 30 30 38 37 0A, then.
awk wouldn't remove the 0x0D but leave it where it was - just before the 87, and thus the 87 should be printed at BOL (begin of line).

What OS/shell/awk versions do you use?
# 3  
Old 06-07-2016
GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2, GNU MP 6.0.0)
Copyright (C) 1989, 1991-2014 Free Software Foundation.

CYGWIN_NT-6.3 STCTQAINFAPP52 1.8.6-2(0.280/5/3) 2014-11-07 09:47 x86_64 Cygwin - I'm actually running Cygwin (Unix emulation) on Windows.

I have attached a picture of the data before/after running the awk command.

Thank you.
Losing carriage return (X0D) after running awk command-awk_file_changejpg
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk Command to add Carriage Return and Line Feed

Hello, Can someone please share a Simple AWK command to append Carriage Return & Line Feed to the end of the file, If the Carriage Return & Line Feed does not exist ! Thanks (16 Replies)
Discussion started by: rosebud123
16 Replies

2. Shell Programming and Scripting

Awk to remove carriage return from 65th field

Hi, I have a pipe delimited file. There are around 700 columns in the file. The 65th column has carriage return which is causing read issue with our ETL process. I would like to replace the new line characters in 65th field with "nothing" i have return the following code and need help to... (7 Replies)
Discussion started by: pinnacle
7 Replies

3. Shell Programming and Scripting

Search_Replace with a Carriage Return

Hey folks, I've been working on this for some time. Seems simple, but I'm stumped. I need the following data format: New_York:Commercial Geology Geophysics Petrophysics Production_Engineering Reservoir_Engineering Pasadena:Commercial ... (5 Replies)
Discussion started by: leepet01
5 Replies

4. Shell Programming and Scripting

refine awk command in replacing carriage return

Hi, need your help in below,I have 4 types of file need to be processed so that it will replace carriage return in Remarks column with <:::> Remarks column position may varies in different types of file. sample file: col1|col2|col3|col4|col5|col6|col7|Remarks|col9|col10... (8 Replies)
Discussion started by: agathaeleanor
8 Replies

5. Shell Programming and Scripting

Why sed command deletes last line in a file if no carriage return?

Hi I am using sed command to make SCORE=somevalue to SCORE=blank in a file. Please see the attached lastline.txt file. After executing the below command on the file, it removes the last line. cat lastline.txt | sed 's/SCORE=.*$/SCORE=/g' > newfile.txt Why does sed command remove the... (3 Replies)
Discussion started by: ashok.k
3 Replies

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

7. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. Shell Programming and Scripting

tcl command to supply a carriage return

I have a java program that runs on a unix server that prompts the user for input and provides a default value to the user. So it does something like this: Enter source server name <source_server_name>: Enter target server name <target_server_name>: I just hit enter to take the default... (1 Reply)
Discussion started by: progkcp
1 Replies

10. Shell Programming and Scripting

Carriage return on long awk operation

hello all I have long awk function that doing manipulations on text file but when I write the out put to new text file I have carriage return between 2 print commands How can I avoid this ? Here is my awk : echo $f | awk... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question