How to print in newline through script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print in newline through script?
# 1  
Old 01-09-2012
How to print in newline through script?

For Example,
Code:
echo `date` >  test.txt

echo $hostname>> SuccessLogin.txt; echo '\n'login is successful>> SuccessLogin.txt

echo $hostname>> FailureLogin.txt; echo '\n'login is failure>> failureLogin.txt

now i want to print the O/P in newline for every host i logged into, then i have to write in SuccessLogin.txt.

Please Advise..
Thanks in Advance


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 01-09-2012 at 08:24 AM.. Reason: code tags
# 2  
Old 01-09-2012
If running the script with sh shell , then use $ echo "\n login is success" >> SuccessLogin.txt

If running with ksh (or) bash shells, then try the below ..
Code:
$ echo "" >> SuccessLogin.txt ; echo "Login is successful" >> SuccessLogin.txt

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 01-09-2012
Might not understand your question. Are you trying to get $hostname and the message output on the same line?
Code:
echo "${hostname} login is successful" >> SuccessLogin.txt

Or if you want to see it on the screen and write to the log at the same time.
Code:
echo "${hostname} login is successful" |tee -a SuccessLogin.txt

# 4  
Old 01-09-2012
Code:
echo -e "line1\nline2"

# 5  
Old 01-09-2012
Not all systems have echo -e, but nearly everything has printf. So:

Code:
printf "%s" "line1\nline2\nline3\n"

Note how every line needs \n, including the very last one. printf never prints newlines unless you tell it to.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk print in script

Hi, Thanks to RudiC I have a functioning awk portion of a script which reads a text file and replaces all matching values in an XML. I need help with placing print statements in the script to see line by line what is being replaced. Script: #!/bin/sh if then echo else ... (7 Replies)
Discussion started by: ocbit
7 Replies

2. Shell Programming and Scripting

Script for removing newline character from file

Hi below is my file. cat input.dat 101,abhilash,1000 102,prave en,2000 103,partha,4 000 10 4,naresh,5000 (its just a example file) and my output should be: 101,abhilash,1000 102,praveen,2000 103,partha,4000 104,naresh,5000 below is my code cat input.dat |tr -d '\n' >... (6 Replies)
Discussion started by: abhilash_nakka
6 Replies

3. UNIX for Dummies Questions & Answers

Print a newline after first match in line

Hi everyone I have a file where CP occurs both within each line and at the very end: dwer 17 knsdask= * CP hwla 17 h'wopie un CP I would like to separate the line on the first CP to get: dwer 17 knsdask= * CP hwla 17 h'wopie un CP What I have so far is: awk '{for (x=1; x<NF; x++) ... (5 Replies)
Discussion started by: meet77
5 Replies

4. Shell Programming and Scripting

Script using Sed :Search all patterns & after the last Patter, insert a newLine with Comma Sep Value

I am trying to search the pattern "ARS (11)" and after the LAST pattern, i am trying to open new line and enter text using sed. My Existing Text file is Users.txtpaul, Paul Smith, Stevn Smiley, REQ000001, ARS (11) sam, Sam Martin, Stevn Smiley, REQ000001, ARS (11) mike, Mike Conway, Stevn... (8 Replies)
Discussion started by: evrurs
8 Replies

5. HP-UX

glance adviser suppress newline in print command

Hi, I have a glance adviser, the highlights below. The problem that i have is that every time glance finds process name "abc" it write the memory region data in a new line. My question is if i have a way to print without newline? The output line for process abc looks something like this:... (0 Replies)
Discussion started by: yochaia01
0 Replies

6. Shell Programming and Scripting

How can I add a newline In a text file using Shell Script

Good day ... Well i do have this project in school, in our Principles Of Operating System Class We are using Cygwin.... And our project goes like this... Create a dictionary using cygwin. Display the following menu at the start of execution 1-add a word in the dictionary # specify the... (1 Reply)
Discussion started by: kpopfreakghecky
1 Replies

7. UNIX for Dummies Questions & Answers

How can I add a newline In a text file using Shell Script

Good day ... Well i do have this project in school, in our Principles Of Operating System Class We are using Cygwin.... And our project goes like this... Create a dictionary using cygwin. Display the following menu at the start of execution 1-add a word in the dictionary # specify... (1 Reply)
Discussion started by: kpopfreakghecky
1 Replies

8. Shell Programming and Scripting

Newline in my script-built shell variable

Hi all, I'm not exactly a shell script guru, so this is probably a very silly question and I'm not seeing the point, but you know, sometimes it happens... I have this script which adds entries to local arp cache using it to find the corresponding IP address. # export MAC=00:25:90:34:3d:f2... (16 Replies)
Discussion started by: micantox
16 Replies

9. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

10. Shell Programming and Scripting

Newline "\n" in shell script.

I'm doing a ksh shell script and I can't figure out for the life of me how to insert a "\n" newline into a shell script's string variable. I wish I could say: someVar="a string\nmore words" echo $someVar However when I do this, I can only get the exact output of: a string\nmore words ... (2 Replies)
Discussion started by: mrwatkin
2 Replies
Login or Register to Ask a Question