new line in echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting new line in echo
# 1  
Old 03-12-2008
new line in echo

Hi
i would like disply the new line in echo command.

i have input like:
echo " X1 02:12:13 X2 03:02:12 "

out put:

X1 02:12:13
X2 03:02:12

can you tell how can use new line option in echo command.
# 2  
Old 03-12-2008
You can enter a new line like this.

Code:
echo "\n"

# 3  
Old 03-12-2008
Code:
echo "X1 02:12:13\nX2 03:02:12"

Regards
# 4  
Old 03-25-2008
Actually, not all versions of echo permit backslash escape codes, but all versions of the shell should allow newlines inside quoted strings.

Code:
echo "X1 02:12:13
X2 03:02:12"

Yup, that's a newline smack dab in the middle of the quoted string.
# 5  
Old 12-27-2008
Pass the -e parameter to enable interpretation of backslash escapes(which us off by default). Like this:
PHP Code:
echo -"hello\nworld!" 
Jostein Topland
# 6  
Old 12-27-2008
Quote:
Originally Posted by jtopland
Pass the -e parameter to enable interpretation of backslash escapes(which us off by default). Like this:
PHP Code:
echo -"hello\nworld!" 

The -e option is not standard. A POSIX-compliant echo does not accept any options:

Code:
$ echo -e "12 34\n56 78"
-e 12 34\n56 78

The simplest and most portable way is to use printf:

Code:
string="12 34\n56 78"
printf "%b\n" "$string"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

2. UNIX for Dummies Questions & Answers

Echo does not work to append to a new line

Hi, i am witing a function in a shell script which will echo the file name and witre in to the new line, but i dont get expected results. The below is my code #!/bin/bash DATE=$1 myview(){ base_name=$1 echo -ne "${base_name}${DATE}">> /path/to/file/txt } myview sample3030 myview... (5 Replies)
Discussion started by: vikatakavi
5 Replies

3. UNIX for Dummies Questions & Answers

New line in Echo command

Hi , This might sound little familar to you guys, but am struck with something. i have an IF conditioned loop which will determine a variable to get used in the later part of the script. if ; then if ; then Var_name="This is first line.This is second line.This is... (11 Replies)
Discussion started by: scott_cog
11 Replies

4. Shell Programming and Scripting

How to read in a part of an echo line?

Hello, I have a very basic script #!/usr/bin/ksh while print ' ' print ' 1. View Command History ' print ' 2. List files in current Directory ' read opt'?Enter Option> ' ;do if ;then fc -l fi # if ;then ls -la I want to... (10 Replies)
Discussion started by: Grueben
10 Replies

5. Shell Programming and Scripting

echo two command output in the same line

Hi, I try to write script and echo two command at the same line . echo "A" echo "B" How can I pipe above two command at the same line in text file . So, in the output text file , you can see below ??? A B not A B Any sugggestion ??? (4 Replies)
Discussion started by: chuikingman
4 Replies

6. Shell Programming and Scripting

Echo and a command's output on the same line

Hello, I'm writing some bash scripts and I'm trying to get an echo command and the output of another command to display on the same line. For example: I want to run echo "Operating System: " unameand have it displayed as Operating System: Darwin Thanks for your help! (7 Replies)
Discussion started by: codyhazelwood
7 Replies

7. UNIX for Advanced & Expert Users

echo and new line

hi I want to display: The students are: a b c What I get from echo "The students are:" "$list" is The students are: a b c any idea? (6 Replies)
Discussion started by: melanie_pfefer
6 Replies

8. Shell Programming and Scripting

Output of both the echo statement in one line

I have script like echo -n FINISHED FEXP: ${TABLE2EXP} echo $STATUS I want the output of both the echo statement in one line How can i do this (3 Replies)
Discussion started by: scorp_rahul23
3 Replies

9. Shell Programming and Scripting

echo just 1 line before execution/set +-x

Suppose that you want to mostly not echo commands inside your script during execution (e.g. to not bog the user down with details that they do not care about) but that there is the occaisional script line that you would like to echo before you execute it. Is there an elegant way to achieve this?... (3 Replies)
Discussion started by: fabulous2
3 Replies

10. Shell Programming and Scripting

how to echo the file contents LINE BY LINE

hello, i have a listing (let say ABC) consists of the below: : public database link public synonym role rollback segment : when i run the below for loop, for i in `more ABC` do echo "$i" done it gives me, : public database (4 Replies)
Discussion started by: newbie168
4 Replies
Login or Register to Ask a Question