Newline charachter in Ksh-Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newline charachter in Ksh-Linux
# 1  
Old 01-17-2010
Newline charachter in Ksh-Linux

Hello,

I'm trying to create a muliti value shell variable with newlines inside it, So that I can read the values of that variable individually line by line, but KSH seems to be stripping my variable of newlines in LINUX, but UNIX its working fine.

Here's Example :

Code:
String = "Hello\n""How R U"

echo "$String" |\
   while read _line
   do
     echo $_line
  done

Output in Unix : Hello
Code:
How R U

But In Linux :
Code:
Hello\nHow R U

Please help in solving this.

Thanks!!!!

Last edited by pludi; 01-18-2010 at 02:02 AM.. Reason: code tags, please...
# 2  
Old 01-18-2010
Hello,

Try:
Code:
echo -e "$String" |\
...

see man 1 echo

Loïc.
# 3  
Old 01-18-2010
Sorry , this is not working !!!
# 4  
Old 01-18-2010
Try:
Code:
String="Hello\nHow R U"
printf "$String\n" |
while read _line
do
  echo $_line
done

Careful when you assign a value to String: spaces around the =-operator are not allowed..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ksh on UNIX and Linux

Hello, Would the same version of Korn Shell (let's say ksh93) would use the same syntax on UNIX and LINUX and work exactly the same? Thanks (3 Replies)
Discussion started by: rdogadin
3 Replies

2. Linux

LINUX Cron Schedule - Newline character issue

we have one simple script that works fine as expected while running it manually. However, it does not work the way it should be when scheduled through CRON. Script: a="Perform" b="Test" output="$a\n$b\n" echo "$output" while executing the above script, it should print the values of a and b... (2 Replies)
Discussion started by: jansat
2 Replies

3. Linux

clear in Linux ksh

Clear in Linux #!/usr/bin/ksh am using clear in the script, but it is not working, it gives an error as follows, 'xterm': unknown terminal type. please help out.:confused: ---------- Post updated at 01:19 PM ---------- Previous update was at 12:01 PM ---------- if then ... (2 Replies)
Discussion started by: pradebban
2 Replies

4. Shell Programming and Scripting

Convert special charachter ^C to new line

Hi, I have a file, which contains ^C or ^A characters from mainfrme system, it's dec 192 or octal 300 hex C0. I want to replace this character with new line. I used commands, but it didn't worked. tr '\o300' '\n' <t >t2 #or tr '\xC0' '\n' <t > t2 Can somebody help me to do... (2 Replies)
Discussion started by: vnag97
2 Replies

5. Shell Programming and Scripting

delete line upto the nth occurence of a particular charachter.

hi all i want to delete a line upto a particular character. here is example. cp cms/images/wifi-zone.png i want to delete the line till . (cp cms/images/wifi-zone.) so the output wud be "png" only how can i do it? also please note down that dot (.) can also occur multiple... (12 Replies)
Discussion started by: kashifv
12 Replies

6. Shell Programming and Scripting

Need to cut filename in LINUX ksh

Hi, I need to cut filename in Linux ksh. for example file name is c_xxxx_cp_200908175035.zip. I need to get variable with only c_xxxx_cp value. (10 Replies)
Discussion started by: juliyp
10 Replies

7. Shell Programming and Scripting

sed ksh remove newline between 2 containers

If we assume that each line between the {} container is an XML document then What I want to remove the newline character from all lines within each container to have one XMDL document per line I wrote a bit of sed after trawling the web: e.g. #!/bin/sed -nf H /}/ { x s/\n//g p... (3 Replies)
Discussion started by: JamesJSC
3 Replies

8. Shell Programming and Scripting

problem escaping newline in ksh

Hi, I did the below. $ print "\\n" $ I am curious, why does \\n give two new lines? I would have thought that the first \ would escape the second \, and so we'd get \n printed. But we didn't. Any ideas? Thanks. (7 Replies)
Discussion started by: JamesByars
7 Replies

9. Shell Programming and Scripting

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. (11 Replies)
Discussion started by: sanikv
11 Replies

10. UNIX for Dummies Questions & Answers

Counting occurences of specific charachter in a file

Hi, I need to count the number of occurences of the character " in a file that contains huge number of records. What command could I use? Please specify in detail since I am new :| Thanks much. (3 Replies)
Discussion started by: GMMike
3 Replies
Login or Register to Ask a Question