Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Wed Aug 23, 2017 8:46 am


Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

Author Message
mandrei99
Post  Post subject: Echo new line in linux - supress new line or echo multiple new lines  |  Posted: Wed Jan 14, 2015 5:26 pm

Joined: Tue Aug 04, 2009 9:16 am
Posts: 245

Offline
 

Echo new line in linux - supress new line or echo multiple new lines

Unix implementation of the "echo" command appends a new line character at the end of the echoed text by default.

It can be changed to supress this behavior using the "-n" switch.

Echo can also be used to output one or multiple new lines with the "-e" switch which will make echo interpret "\n" sequence as new line.

Below is a list of multiple options and special sequences with ECHO:
Quote:
DESCRIPTION
Echo the STRING(s) to standard output.

-n do not output the trailing newline

-e enable interpretation of backslash escapes

-E disable interpretation of backslash escapes (default)

--help display this help and exit

--version
output version information and exit

If -e is in effect, the following sequences are recognized:

\\ backslash

\a alert (BEL)

\b backspace

\c produce no further output

\e escape

\f form feed

\n new line

\r carriage return

\t horizontal tab

\v vertical tab

\0NNN byte with octal value NNN (1 to 3 digits)

\xHH byte with hexadecimal value HH (1 to 2 digits)

NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.

Supress new line with echo:
Code:
user@linux:~# echo -n "this is a sentence"
this is a sentenceuser@linux:~#

Echo one or multiple new lines


Code:
user@linux:~# echo -e "Two new lines following this\n\nAnother sentence"
Two new lines following this

Another sentence





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Echo new line in linux - supress new line or echo multiple new lines"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. How to replace \w SED multiple matches on the same line without piping

mandrei99

0

1055

Tue Oct 08, 2013 6:29 am

mandrei99 View the latest post

There are no new unread posts for this topic. SED uncomment line - How to uncomment a line or all lines with SED

mandrei99

0

3317

Wed Jan 14, 2015 5:08 pm

mandrei99 View the latest post

There are no new unread posts for this topic. How to echo newline in Linux/Unix shell

mandrei99

0

16736

Tue Jun 25, 2013 5:58 am

mandrei99 View the latest post

There are no new unread posts for this topic. Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL

mandrei99

0

548

Mon Jan 12, 2015 12:01 pm

mandrei99 View the latest post

There are no new unread posts for this topic. SED how to remove multiple white spaces from a string

debuser

0

6912

Thu Feb 25, 2010 7:14 am

debuser View the latest post

There are no new unread posts for this topic. Remove empty lines in vi/vim

debuser

0

525

Mon Apr 26, 2010 11:06 am

debuser View the latest post

There are no new unread posts for this topic. Using sed to comment/uncomment lines in files

debuser

0

5061

Fri Apr 02, 2010 6:07 am

debuser View the latest post

There are no new unread posts for this topic. Unix shell - using TR to replace new lines with spaces

debuser

0

4865

Thu Feb 25, 2010 8:08 am

debuser View the latest post

There are no new unread posts for this topic. How to replace new line in perl script

mandrei99

1

1816

Wed Jun 26, 2013 8:18 am

admin View the latest post

There are no new unread posts for this topic. How to convert a text into a list of words, one per line

LaR3

0

4446

Wed Aug 05, 2009 7:02 am

LaR3 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO