Operating System - HP-UX
1825805 Members
2373 Online
109687 Solutions
New Discussion

Re: query on vi (LINE FEED)

 
SOLVED
Go to solution
Vin_5
Occasional Advisor

query on vi (LINE FEED)

Hi,

I'm having trouble entering a 'LINE FEED' into a script:

OUTPUT="$FIRST $SECOND"

The application I'm sending the output to interprets 'LINE FEED' (0x0A, 10) as carriage return, however when I edit the script (vi, ctrl-V, ctrl-J as per 'man ascii') the '^J' is not displayed, instead:

OUTPUT="$FIRST
$SECOND"

'^M' is displayed correctly but does not produce the required output. Any ideas where I'm going wrong?

Many Thanks.

13 REPLIES 13
Ollie R
Respected Contributor

Re: query on vi (LINE FEED)

Hi Vin,
"vi" WILL show ^J as a new line. That's what it means.
What exactly are you trying to do with the output?
Ollie.
To err is human but to not award points is unforgivable
Jean-Louis Phelix
Honored Contributor

Re: query on vi (LINE FEED)

hi,

If you're writing a script, why don't you use symbolic forms ?

I'm not sure of what you want, but you could perhaps simply use :

OUTPUT="$FIRST\rSECOND" or OUTPUT="$FIRST\n$SECOND"

Regards.
It works for me (© Bill McNAMARA ...)
Darren Prior
Honored Contributor

Re: query on vi (LINE FEED)

Hi,

It sounds like your application may be PC based, hence interprets the CR/LF differently from your HP-UX based script. You could use ux2dos to convert the output from LF to CR/LF which will then look correct in your application.

regards,

Darren.
Calm down. It's only ones and zeros...
Ollie R
Respected Contributor

Re: query on vi (LINE FEED)

Hi Vin,

Having looked at your original message again, I think I understand what you're trying to do.

Please could you try the following and see if this is what you're trying to achieve?

FIRST=first
SECOND=second
OUTPUT="$FIRST\012$SECOND"
echo $OUTPUT

Ollie.
To err is human but to not award points is unforgivable
Vin_5
Occasional Advisor

Re: query on vi (LINE FEED)

Hi,

What I need the script to forward to the application is HEX 0A, so:

OUTPUT="$FIRST<0A>$SECOND"

HEX 0A = LINE FEED = ^J

However, when I insert the ^J by doing the following, I do not receive 0A:
-vi file
-ctrl-V
-ctrl-J

Is it the editor? Entering '\n' '\r' won't work unfortunately.

Thanks again.

Ollie R
Respected Contributor

Re: query on vi (LINE FEED)

Hi Vin,
Try my previous reply - OCTAL 12 \012
Ollie.
To err is human but to not award points is unforgivable
Vin_5
Occasional Advisor

Re: query on vi (LINE FEED)

Hi Ollie,

No luck unfortunately, I see what you mean though. Is it possible to do something similar except specify 'HEX 10 (\?10)' instead of 'OCT 12 (\012)'?

Cheers.
Darren Prior
Honored Contributor
Solution

Re: query on vi (LINE FEED)

Hi Vin,

Those 2 numbers are equal, both represent ASCII value 10 (decimal), ie ^J.

Have you tried piping your script through od -tax; it'll show you the hex values and ascii characters that are being echoed?

regards,

Darren.
Calm down. It's only ones and zeros...
Ollie R
Respected Contributor

Re: query on vi (LINE FEED)

Hi,
Why do you want to do HEX 10? That's a backspace!
If you want a newline (OCTAL 12) then the suggestion I give above will work.
What else are you trying to do?
Ollie.
(P.S. How about a bit of points assignment? I'm trying to get my cap today!)
To err is human but to not award points is unforgivable
Ollie R
Respected Contributor

Re: query on vi (LINE FEED)

Oops! OCT 10 is backspace - sorry!

HEX 10 is "dle" (whatever that means).
To err is human but to not award points is unforgivable
Massimo Bianchi
Honored Contributor

Re: query on vi (LINE FEED)

Hi,
why don't you try with redirection ?


your_command << EOF
$FIRST
$SECOND
EOF


HTH,
Massimo

Jean-Louis Phelix
Honored Contributor

Re: query on vi (LINE FEED)

Hi,

It's quite strange, because if you control the output using od it seems to work (either with \code or \n).

$ N="FIRST\nSECOND"
$ echo $N | od -cb
0000000 F I R S T \n S E C O N D \n
106 111 122 123 124 012 123 105 103 117 116 104 012
$ N="FIRST\012SECOND"
$ echo $N | od -cb
0000000 F I R S T \n S E C O N D \n
106 111 122 123 124 012 123 105 103 117 116 104 012


Regards.
It works for me (© Bill McNAMARA ...)
Vin_5
Occasional Advisor

Re: query on vi (LINE FEED)

Found the problem using 'od -tax', now all combinations work!

My app wasn't padding out HEX fields with zero, so when the Line Feed was submitted it was passed along as 'A' instead of '0A' and messed everything else up!

Many thanks to all who replied.