Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use sed to insert non-printing chars 1

Status
Not open for further replies.

kasparov

Programmer
Feb 13, 2002
203
GB
What's the syntax to insert a non-printing char (e.g. octal 012) into a string? I've tried things like:

Code:
# date 
Wednesday June 25 14:17:22 BST 2008
# date | sed 's/BST/\012/'
Wednesday June 25 14:17:47 012 2008
#

but whatever I try it doesn't substitute to the single ascii character (this exampe would hopefully split the line but there are other non printing chars I want to insert into a string).

I'm using ksh on Solaris 8 (I could use other shells if required).

Thanks in advice, Chris
 
Hi

Code:
date | sed 's/EEST/\[red]o[/red]012/'
info sed said:
`\dXXX'
Produces or matches a character whose decimal ASCII value is XXX.

`\oXXX'
Produces or matches a character whose octal ASCII value is XXX.

`\xXX'
Produces or matches a character whose hexadecimal ASCII value is XX.

Feherke.
 
What about this ?
date | awk '{sub(/BST/,"\n");print}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply feherke - Unfortunately I'd tried that & what I get is:

Code:
# date | sed 's/BST/\o012/'
Wed Jun 25 14:58:25 o012 2008
#

This is with ksh - I've also tried csh & sh but they all give me the same. Maybe my version of sed? Not sure how I find out that though.

PHV - I got a syntax error with awk but nawk looks like it's nearly there. It works for "\n" but I want to do this for other non-printing chars too - do you know how I could achieve the same using octal 012 instead of \n? (I've tried "\0012", "\o012" & with ' instead of " but no joy)

Thanks again everyone
 
date| nawk '{sub(/BST/,"\012");print}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top