APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

passing null characters sed

What is this stuff?

If this isn't exactly what you wanted, please try our Search (there's a LOT of techy and non-techy stuff here about Linux, Unix, Mac OS X and just computers in general!):

Newsgroups: comp.unix.sco.misc
Subject: Re: Why can't I echo control codes with SED
References: <HhhO5.102$B55.19058755@news1.pvt.primus.ca> 
From: spcecdt@deeptht.armory.com. (John DuBois)
Message-ID: <_2oO5.204$34.9914@e420r-sjo3.usenetserver.com> 
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
Date: Thu, 09 Nov 2000 02:34:34 GMT

In article <HhhO5.102$B55.19058755@news1.pvt.primus.ca>,
Dean Northam <alltemp@globalserve.net> wrote:
>I tried text2post for a form overlay but dropping in the eps in the right
>point in the postscript language is frustrating at best and I hit a brick
>wall with it. I've now switched gears to enscript and have better luck so
>far with it. Only problem is when I try to insert a "\000" into my print out
>I get "\200", so I thought I would dump it thru sed and do a search and
>replace. But it seems to me that sed does not like control codes very much.
>So far I have this but the control codes are NOT being captured:
>sed 's/\\200epsf/'`echo "\000"`'epsf/' $file |
> /usr/local/bin/enscript -B -e -fCourier12@11.6 -p-
>all that ends up in the files is "epsf[n]{/tmp/test.eps}"

There are a couple of things wrong with this.  First, under no circumstance
can a null character be passed in the argument vector to an exec'd program,
which is what you're trying to do when you give these arguments to an
executable on the command line.  The strings in the argument vector are
terminated by nulls, so nulls can't be embedded in them; see exec(S).

You could try to work around this by including them in a script file, but it
still wouldn't work, because sed can't deal with nulls in its program.  It,
too, uses nulls to terminate strings.

awk, as well, can't introduce nulls into its output, but gawk can.

Interestingly, tr discards nulls from its input, but can introduce them into
its output.  If you don't actually need the 'epsf' context, and your input
will never include null characters, use this:

tr '\200' '\0' < $file | enscript ...

Otherwise, get gawk and use something like:

gawk '{gsub("\200epsf","\0epsf");print}' $file | enscript ...

John DuBois  spcecdt@armory.com.  KC6QKZ/AE  http://www.armory.com./~spcecdt/

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> passing null characters sed ––>Re: Why can't I echocontrol codes with SED

Increase ad revenue 50-250% with Ezoic

Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

I wanted to learn how to swim, so Google showed me how to turn on the water at the sink and let me splash it around a bit. They then dragged me into a helicopter, flew way out into the ocean and dumped me out. (Tony Lawrence)

This post tagged: