Printf transforms \x0a into \x00


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printf transforms \x0a into \x00
# 1  
Old 12-30-2012
Printf transforms \x0a into \x00

If

Code:
printf '\x0a' | xxd -cols 1

produces

Code:
0000000: 0a  .

then, why does

Code:
printf '%c' "`printf '\x0a'`" | xxd -cols 1

produce

Code:
0000000: 00  .

??
# 2  
Old 12-31-2012
Quote:
Originally Posted by vomv1988
If

Code:
printf '\x0a' | xxd -cols 1

produces

Code:
0000000: 0a  .

then, why does

Code:
printf '%c' "`printf '\x0a'`" | xxd -cols 1

produce

Code:
0000000: 00  .

??
Because command substitution (`command` or $(command)) removes trailing newlines from the output of the commands performed.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 3  
Old 12-31-2012
Quote:
Originally Posted by Don Cragun
Because command substitution (`command` or $(command)) removes trailing newlines from the output of the commands performed.
I didn't know that! Thanks for the info.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Perl] Does m/\x0A/ same as m/\x{0A}/ ?

Perl allow hex character with just one digit. Such as \x0 \x9 \xA. How to force to use 2 digits in m// and s///. Such as \x00 \x09 \x0A. ---------- Post updated at 05:20 PM ---------- Previous update was at 03:38 PM ---------- I don't know why these code replace as text, not a real hex... (0 Replies)
Discussion started by: natong
0 Replies

2. Virtualization and Cloud Computing

Install Xen vm on centos5.5 crashed "x00\x00\x00\x00\"

Hi, everyone: I'm new to xen. When I install a vm on centos5.5, I got xen crashed: # virt-install -n centos5 -r 512 --vcpus=1 --disk path=/home/mycoy/centos5.img,size=8 --nographics -l http://mirror01.idc.hinet.net/CentOS/5.5/isos/i386/CentOS-5.5-i386-netinstall.iso when... (1 Reply)
Discussion started by: mycoy
1 Replies

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

4. Shell Programming and Scripting

remove \x0a in unix

hi all, i have a flat file delimited by pipe (|), and i'm loading it to sybase, the problem is when i do a select to the table of the database, the last field has new line ascii (\x0a): 38,'0\x0a ' 88,'076004074028\x0a ' 27,'076004075023\x0a ' how can i remove the \x0a from... (1 Reply)
Discussion started by: DebianJ
1 Replies

5. Shell Programming and Scripting

[AWK] read lines with \x00 symbol

I want to read a large (~1-4Gb) txt file with fields separated by "," and line separator "\n". Unfortunately, file contains \x00 (zero ASCII) symbols AWK treats them as end of line + it ignores reminder of the line after the \x00. As a simple example: echo "\0060\0061\000\0060\0063" | nawk... (6 Replies)
Discussion started by: Murfury
6 Replies

6. Programming

printf

What is the output of the following program considering an x86 based parameter passing sequence where stack grows towards lower memory addresses and that arguments are evaluated from right to left: int i=10; int f1() { static int i = 15; printf("f1:%d ", i); return i--; } main() {... (2 Replies)
Discussion started by: arunviswanath
2 Replies
Login or Register to Ask a Question