Re: string format

2009-09-24 Thread mahaveer darade
given below will work except tab at beginning.

 echo "Hello, how are you  doing today?" |  tr -s " " "\n"


Thanks,
Mahaveer
+91 9052000707

On Thu, Sep 24, 2009 at 12:33 AM, eatsubway  wrote:

>
> hello, i have a simple question.  I have a string which i would like to
> format by replacing spaces with newlines and tabs, and also adding a tab to
> the beginning.
>
> the variable...
> MyVar="Hello, how are you doing today?"
> I would like to print this
>
>   Hello,
>   how
>   are
>   you
>   doing
>   today?
> --
> View this message in context:
> http://www.nabble.com/string-format-tp25531252p25531252.html
> Sent from the Gnu - Bash mailing list archive at Nabble.com.
>
>
>
>


-- 
Thanks,
Mahaveer


Re: string format

2009-09-23 Thread Mike Stroyan
On Wed, Sep 23, 2009 at 12:03:56PM -0700, eatsubway wrote:
> 
> hello, i have a simple question.  I have a string which i would like to
> format by replacing spaces with newlines and tabs, and also adding a tab to
> the beginning.

  The printf builtin will do that easily.  If you give it a format with one
argument then it will repeat that format for each of multiple arguments.

printf "\t%s\n" $MyVar

  If you really want to only break up your string at spaces then you will
want to momentarily change IFS to just " " instead of the default that
matches spaces, tabs, and newlines.  Be sure to put IFS back to the
default for the benefit of later parts of your shell script that expect
the default.  You can do that with another assignment or with a subshell
like this-

( IFS=" "; printf "\t%s\n" $MyVar )

-- 
Mike Stroyan 




string format

2009-09-23 Thread eatsubway

hello, i have a simple question.  I have a string which i would like to
format by replacing spaces with newlines and tabs, and also adding a tab to
the beginning.

the variable...
MyVar="Hello, how are you doing today?"
I would like to print this

   Hello,
   how
   are
   you
   doing
   today?
-- 
View this message in context: 
http://www.nabble.com/string-format-tp25531252p25531252.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.