Formatting echo o/p


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting echo o/p
# 1  
Old 10-08-2014
Formatting echo o/p

Hi Team,

Need a small help. I want to format my echo o/p. let say

Code:
echo "[Daily]       helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo helo "

I want o/p to be displayed in below format
Code:
[Daily]       helo helo helo helo helo helo helo helo helo helo helo helo helo 
                 helo helo helo helo helo helo

Moderator's Comments:
Mod Comment If you want formatted output; it is absolutely crucial that you use CODE tags so we can actually see the format you want.

Last edited by Don Cragun; 10-08-2014 at 01:57 AM.. Reason: Add CODE tags.
# 2  
Old 10-08-2014
Code:
echo -e "[Daily] helo helo helo helo helo helo helo helo helo helo helo helo helo\n helo helo helo helo helo helo "

# 3  
Old 10-08-2014
Thanks for your reply. When I tried the way you said but it is not working.
Code:
[ldn005@gvkumar25]echo -e "[INFO]   helllllllo helllllo \n hw r u"
-e [INFO]   helllllllo helllllo
 hw r u

--------------------------
but I need the output to be in below format
Code:
([INFO]    helllllllo helllllo
               hw r u)

one more question is if my echo statement contains more character i want it to be formatted automatically in the above way

---------- Post updated at 12:20 AM ---------- Previous update was at 12:12 AM ----------

Code:
[INFO]    helllllllo helllllo
          hw r u


Last edited by Franklin52; 10-08-2014 at 11:39 AM.. Reason: Adding code tags
# 4  
Old 10-08-2014
You did not specify what OS or shell you're using. The behavior of echo varies considerably from OS to OS and shell to shell.

Although what Aia suggested will work on some systems using some shells, any echo that conforms to standard requirements would print the output:
Code:
-e [Daily] helo helo helo helo helo helo helo helo helo helo helo helo helo\n helo helo helo helo helo helo

if given that echo command.

As long as the strings you want to print do not contain any backslash characters and the 1st character to be printed is not a hyphen (as in your desired output), you could portably use two echo commands:
Code:
echo "[Daily]       helo helo helo helo helo helo helo helo helo helo helo helo helo "
echo "                 helo helo helo helo helo helo"

Anytime you are printing data that contains any backslashes or data that starts with a hyphen, you should use printf instead of echo.
# 5  
Old 10-08-2014
I am using korn shell and OS--AIX

Code:
[ERROR]   Supplied invalid Parameters
[ERROR]   Supplied Input file is a zero byte file.
 Usage  File_protocal.sh -c<Configuration file name  need to be specified   > <-d file  configuration file delimeter need to be specified> -s<Source directory where transfer files are generated>

---------- Post updated at 01:00 AM ---------- Previous update was at 12:51 AM ----------

I want to format above output.


Code:
[ERROR]   .......  
          .......
[ERROR]   ......

# 6  
Old 10-08-2014
Code:
echo "\
[Daily]     helo helo helo helo helo helo helo helo helo helo helo helo helo
                helo helo helo helo helo helo"


Last edited by MadeInGermany; 10-08-2014 at 04:21 AM.. Reason: added spaces
# 7  
Old 10-08-2014
This is a CygWin test but might work with your echo version:-
Code:
#!/bin/sh
newline="
"
echo "This is a line...$newline              And this is another line."

results:-
Code:
AMIGA:~> cd /tmp
AMIGA:/tmp> chmod 755 echo_format.sh
AMIGA:/tmp> dos2unix echo_format.sh
dos2unix: converting file echo_format.sh to Unix format ...
AMIGA:/tmp> ./echo_format.sh
This is a line...
              And this is another line.
AMIGA:/tmp> _

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between echo `ls -l` and echo "`ls -l`" ?

Hi guys, Been messing around with shell programming for a couple of days and I found something that was pretty odd in the behavior of the echo command. Below is an example-: When I type the following in my /home directory from my lxterminal in Debian-: echo "`ls -l`" I get the... (2 Replies)
Discussion started by: sreyan32
2 Replies

2. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

3. Shell Programming and Scripting

Formatting Help

Hi Guys, i have report that runs every 10 min and send the report of failed jobs to my mail. Currently i am using a command like this to send mail. mailx -t -s "FAILURE JOBS IN HYDRA $temp_date" addressee@domain.com < temp_file5 But i am getting mail in this format ....... (4 Replies)
Discussion started by: gkrish
4 Replies

4. Shell Programming and Scripting

help formatting

I need to format a txt file and convert it in CSV. Any "future" column is separated by a newline. FROM: XS1 1.43294 0.0 XS2 1.21824 0.0 TO: XS1,XS2 (2 Replies)
Discussion started by: alfreale
2 Replies

5. Shell Programming and Scripting

formatting of df -k

Hello, I am developing a platform Independant tool that should work for all major unix flavors outlined in this forum(Solaris,Linux, AIX, HPUX, SCO,BSD) Therefore, in order to cover all types of user community, I have deliberately posted the same message on every forum. Please do not think... (9 Replies)
Discussion started by: darsh123
9 Replies

6. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

7. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

8. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

9. Shell Programming and Scripting

formatting output using echo

i have the following script: while ;do b=${ARRAY2} i=0 while ;do a=${ARRAY1} fin=`echo $a - $b | bc` echo -e "${fin}," >> try ((i++)) ((k++)) done echo -n >> try #add statement to format output here #printf "\t" >> try #echo -e '\t' >> nik ((j++)) echo $j (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

formatting

I have file with different columns for ex. contents of file "txt" NAME AGE MARKS HARRY 23 89 TOM 12 67 BOB 23 11 and you see its not formatted.Now, I need the file "txt" to be formatted like COLUMN1 COLUMN2 COLUMN3 NAME AGE ... (3 Replies)
Discussion started by: vijay_0209
3 Replies
Login or Register to Ask a Question