It is currently Tue, 30 Nov 2021 16:59:23 GMT



 
Author Message
 echo with CARRIAGE RETURN
Hello

Recently, I tried to write lines to a file using echo, which was to be
used under Windows:

echo \
"The second line is a path\r
path: D:\\DATA\\DOCUS\r
This is the third line\r" > file

But then, the Windows application reading the second line containing
the path demanded a backslach at the end, ie: D:\DATA\DOCUS\
So I rewrote:
echo \
"The second line is a path\r
path: D:\\DATA\\DOCUS\\\r
This is the third line\r" > file

But instead of getting  a DOS type line delimiter, what I got as an
output on the second line contained the backshlash and an r literally:
path: D:\DATA\DOCUS\r

Putting additional backshlashes before \r did not help. Strange.

I ended up doing this:
echo \
"The second line is a path
path: D:\\DATA\\DOCUS\\
This is the third line" | unix2dos > file

and that worked because i got a DOS type line containing the
backshlash and the end of the line, but now I would like how to
produce a CARRIAGE RETURN character using echo...

Using Solaris 2.7

Thanks,
Rick



 Fri, 06 May 2005 04:24:49 GMT   
 echo with CARRIAGE RETURN
    :
    :
    :

"echo" is a shell built-in.  That means, depending on which shell
you are using, you could get one of several different implementations
of "echo", and they don't all behave the same.

I'm going to take a stab and guess that you're using bash.  In
that case, if you're going to use the built-in echo, you need to
specify "-e", as in "echo -e 'xyz\r'".

Alternatively, don't worry about it and just do this:

    {
        echo "The second line is a path"
        echo "path: D:\\DATA\\DOCUS\\"
        echo "This is the third line"
    } |
        unix2dos > file

Since unix2dos is Solaris-only (as far as I Know), you may want
to use awk instead for portability:

    {
        echo "The second line is a path"
        echo "path: D:\\DATA\\DOCUS\\"
        echo "This is the third line"
    } |
        awk '{print $0 "\r"}' > file

Hope that helps.

  - Logan

--
I'm currently looking for work as a Unix/Solaris
administrator, or Perl/C++/Java developer.  Resume
at http://home.austin.rr.com/logan/resume.html.



 Fri, 06 May 2005 10:25:56 GMT   
 
   [ 2 post ] 

Similar Threads

1. echo and carriage returns? <sec>

2. cups and carriage returns

3. Using grep to find PC carriage returns

4. Another simple queries - no carriage return when printing - funny format

5. strip carriage return

6. Adding a carriage return.

7. Strip Carriage Returns

8. Carriage returns in print jobs

9. HELP: ftp carriage return


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software