cancel
Showing results for 
Search instead for 
Did you mean: 

awk escape sequence

SOLVED
Go to solution

awk escape sequence

Hi,

Under HP-UX awk version, the escape sequence \c permits to continue writing to the same line with the next print command ( no carriage return, new line is set)

Under linux, the escape sequence \c doesn't exist so it replace it by a "c" character

awk: cmd. line:5: warning: escape sequence `\c' treated as plain `c'

Does an equivalent escape sequence or other stuff would work?

Thanks in advance
Denis
7 REPLIES
Huc_1
Honored Contributor

Re: awk escape sequence

I am no awk expert far from it

I just know there is a compatibility switch in gawk

awk --compat 'your srcipt'

Probably there are other way's

will have a look

J-P
Smile I will feel the difference

Re: awk escape sequence

--compat or --traditional gaves me the same output problem

Huc_1
Honored Contributor

Re: awk escape sequence

A simple \

Seem's to do it

extarcted from man page

a line can be continued by ending it with a â \â , in
which case the newline will be ignored.

end of extract from man page.

Does that work ?
Smile I will feel the difference
Huc_1
Honored Contributor

Re: awk escape sequence

Sorry about mess up character in previous reply
just did a cut and past from linux man gawk to reply, and should have preview before submit

In my doc here there is also the
-W posix

switch have you tried that ?

If none of the above works for you could attach a small example script that work under HP-UX and does not work under linux... so we can try or hand at this ?

J-P

Smile I will feel the difference
Bob_Vance
Esteemed Contributor
Solution

Re: awk escape sequence

Use 'printf', instead of 'print'.

'printf' does not automatically add a newline to the end of the line and you can format it anyway you want:

mandy-DEB ## echo -e '\n'| awk '{printf NR " hohoho "}'
1 hohoho 2 hohoho

mandy-DEB ## echo -e '\n'| awk '{printf NR " hohoho\n"}'
1 hohoho
2 hohoho
"The lyf so short, the craft so long to lerne." - Chaucer

Re: awk escape sequence

Huc > a backslash at the end of a line permits to continue a statement on a new line ( very useful when long statement are used at prompt) but do not allow to continue the output of the script to be on the same line.
> "-W posix" doesn't seems to change anything as the error message is still the same

Bob > That will do the trick, thank you for this workaround

Thank you all for your help

Regards
Denis
Huc_1
Honored Contributor

Re: awk escape sequence

Nice to know there are some knowledgeable awk reading/answering this forum as I sayed I am no expert, but you got your answer and this allowed me to dig a little in awk and learn more then I could deliver. nice

Thanks for the points.

(Zero points for this answer of course)

J-P
Smile I will feel the difference