Newline character not working for ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newline character not working for ksh
# 1  
Old 06-22-2005
Newline character not working for ksh

Newline character "\n" not working for ksh in linux AS 3.0

Command :

$echo "Hi\nHi"
$Hi\nHi
$

Expected output :
$echo "Hi\nHi"
Hi
Hi
$

Can some help me on this

Thanks in advance
Sanish.
# 2  
Old 06-22-2005
either:
/bin/echo '"Hi\nHi"

or [if in bash]:
echo -e "Hi\nHi"
# 3  
Old 06-22-2005
Or you could always use printf....

printf "Hi\nHi\n"

Note - with printf you'll need a trailing newline too

Cheers
ZB
# 4  
Old 06-23-2005
Hi vgersh99 & zazzybob ,

Thanks for the suggestions.

printf helps to resolve the issue in ksh.

But i have issues with other commands also, so i suspect that there is something to do with the shell i.e setting some environment variables or something.

My main issue is with sed

I am expecting the following output from the follwing command

$ sed -e 's/String1/String0\nString1\nString2/' < aa
String0
String1
String2

But i am getting the following output

$ sed -e 's/String1/String0\nString1\nString2/' < aa
String0nString1nString2

Can you please help me on this
# 5  
Old 06-23-2005
sed -e "s/String1/String0`/bin/echo`String1`/bin/echo`String2/" < aa
# 6  
Old 06-23-2005
Hi vgersh99,

thanks for your response, but it did'nt help

$ cat aa
String1

$ cat x
#!/bin/ksh
sed -e "s/String1/String0`/bin/echo`String1`/bin/echo`String2/" < aa

$ ./x
String0String1String2

Seems that it is ignoring the newline

Thanks,
Sanish
# 7  
Old 06-23-2005
\n is a backslash followed by an n. To the shell, backslash removes any special meaning from the character that follows it. n has no special meaning, so the backslash does nothing and you just get an n.

\\n will cause the shell to send a \n somewhere. A very few programs interpret a \n as a newline and these will document that. Everywhere else it is just a back slash followed by a n.

sed accepts \n in an RE. You are not trying to put \n in an RE. To do you want:

# echo string0 | sed 's/string0/string1\
> string2/'
string1
string2
#
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

3. Shell Programming and Scripting

Scripting for PuttyCM (NewLine Character)

Hi, I am trying to edit a script to create an XML file to upload into PuttyCM. Everything works with the exception of the NewLine character. By default this option is set to Line feed (LF). I need it to be set to NewLine (CR/LF) <options> <loginmacro>True</loginmacro> ... (4 Replies)
Discussion started by: Jett44
4 Replies

4. Shell Programming and Scripting

replacing by newline character

I have a file (pema)with a single long record which i have to break up into multiple lines Input s1aaaaaaaaaaaaaaaaaaaaaaas1bbbbbbbbbbs1cccccccccc Output s1aaaaaaaaaaaaaaaaaaaaaaa s1bbbbbbbbbb s1cccccccccc m planning to do it by replacing s1 by \ns1 \n is the new line character i... (5 Replies)
Discussion started by: pema.yozer
5 Replies

5. Shell Programming and Scripting

Remove newline character between two delimiters

hi i am having delimited .dat file having content like below. test.dat(5 line of records) ====== PT2~Stag~Pt2 Stag Test. Updated~PT2 S T~Area~~UNCEF R20~~2012-05-24 ~2014-05-24~~ PT2~Stag y~Pt2 Stag Test. Updated~PT2 S T~Area~METR~~~2012-05-24~2014-05-24~~test PT2~Pt2 Stag Test~~PT2 S... (4 Replies)
Discussion started by: sushine11
4 Replies

6. UNIX for Dummies Questions & Answers

newline character in a variable

variable="unix\nlinux" echo $variable expected output: unix linux :wall: can i do that ?? thanks in advance!! (3 Replies)
Discussion started by: sathish92
3 Replies

7. Shell Programming and Scripting

Why SED can't see the last newline character?

Removed. My question does not make sense. and SED does see the last newline character. But I still have a question: How to remove the last newline character(the newline character at the end of last line) using SED? ---------- Post updated 05-01-11 at 10:51 AM ---------- Previous update was... (7 Replies)
Discussion started by: kevintse
7 Replies

8. UNIX for Dummies Questions & Answers

echo without newline character

hi, I have a for loop where in I write some file name to another file. I want to write all the filenames to another without any newlines. how can i avoid getting new lines with echo? Thanks, Srilaxmi (2 Replies)
Discussion started by: srilaxmi
2 Replies

9. UNIX for Dummies Questions & Answers

newline character

hi, I want to print the below lines "Message from bac logistics The Confirmation File has not been received." When i give like this in the code "Message from bac logistics\n The Confirmation File has not been received." It is giving only Message from bac logistics\n The... (9 Replies)
Discussion started by: trichyselva
9 Replies

10. UNIX for Dummies Questions & Answers

How can I replace newline character?

Hi, I am trying to write a script to prepare some text for use as web content. What is happening is that all the newlines in the textfile are ignored, so I want to be able to replace/add a few characters so that for a file containg: This is line 1. This is line two. This is line four.... (1 Reply)
Discussion started by: ghoti
1 Replies
Login or Register to Ask a Question