how to keep newline characters in command execution result?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to keep newline characters in command execution result?
# 1  
Old 01-02-2008
how to keep newline characters in command execution result?

I found that when I used a variable to receive the result from a command execution, the newline characters were removed from the variable.

For example, I ran

$ ret=`ls -l`
$ echo $ret

Then, I saw:
total 40 -rw-r--r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk -rw-rw-r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk1

But the output I expected is:
total 40
-rw-r--r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk
-rw-rw-r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk1

So, the question is, how to keep the newline characters in the variable that receives the command result?

Thanks.
# 2  
Old 01-02-2008
Hi.

Use double-quotes around the variable in the echo ... cheers, drl
# 3  
Old 01-02-2008
Quote:
Originally Posted by drl
Hi.

Use double-quotes around the variable in the echo ... cheers, drl
drl, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert newline when grep result is empty

Given a csv file with 40 columns with name, address, hometown etc. I use a bash command in 1 line which: 1. gets the address column and pipes that to 2. grep the first digit and everything that follows Command: awk -F ";" '{print $19}' /Users/jb/Desktop/ReorderTempTotal.csv | grep -o "\d.*"... (7 Replies)
Discussion started by: JBVeenstra
7 Replies

2. Shell Programming and Scripting

Removing newline characters within DEL quotes.

Hi, Text file has DEL character(ASCII code 127) as quotes with comma as field delimiter. If any of the field contains new line character then I need to remove it. Please help me to achieve this. Thanks Vikram (4 Replies)
Discussion started by: Vikramhm
4 Replies

3. Shell Programming and Scripting

Removinf newline characters in first 62 fields

Hi All, I receive a | delimited text file containing 63 columns. There is no delimiter at the end of the 63rd field, instead there would be a newline character at the end of the text in 63rd column. I wanted to retain this newline character at the end of the 63rd column, as it is desired newline... (1 Reply)
Discussion started by: sagarparadkar
1 Replies

4. Shell Programming and Scripting

Newline characters in fields of a file

My source file is pipe delimeted file with 53 fields.In 33 rd column i am getting mutlple new line characters,dule to that record is breaking into multiple records. Note : here record delimter also \n sample Source file with 6 fields : 1234|abc| \nabcd \n bvd \n cde \n |678|890|900\n ... (6 Replies)
Discussion started by: lakshmi001
6 Replies

5. Solaris

grep result in newline

Hi While trying to do a search on solaris, the grep results seems to be appearing on the same line instead of the new line. Wed Jan 18 14:45:48 weblogic@test:/abcd$ grep qainejb02 * qa_cluster_biz_view_tc_intl_servers_ports_2:qainejb02 7101 qa_cluster_servers_2:qainejb02... (2 Replies)
Discussion started by: ganga.dharan
2 Replies

6. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

7. Shell Programming and Scripting

Breaking long lines into (characters, newline, space) groups

Hello, I am currently trying to edit an ldif file. The ldif specification states that a newline followed by a space indicates the subsequent line is a continuation of the line. So, in order to search and replace properly and edit the file, I open the file in textwrangler, search for "\r " and... (14 Replies)
Discussion started by: rowie718
14 Replies

8. Shell Programming and Scripting

deleting newline characters but not the "true" \n character

hi, i have a file that has about 4500 rows. this was an old microsoft access databse and what i am trying to do is take out the old extra \n newline characters but not take out the "true" newline character. I will explain. i was trying to write a regular expression, but that was not... (1 Reply)
Discussion started by: caddyjoe77
1 Replies

9. Shell Programming and Scripting

remove trailing newline characters

Hello , I have the folowing scenario : I have a text file as follows : (say name.txt) ABC DEF XYZ And I have one more xml file as follows : (say somexml.xml) <Name>ABC</Name> <Age>12</Age> <Class>D</Class> <Name>XYZ</Name> <Age>12</Age> <Class>D</Class> <Name>DEF</Name>... (7 Replies)
Discussion started by: shweta_d
7 Replies

10. Shell Programming and Scripting

Formatting a text file based on newline and delimiter characters

Hi Everybody, I need some help on formatting the files coming into unix box on the fly. I get a file some thing like this in a single line. ISA^M00^M ^M00^M ^M14^M006929681900 ^M01^M095449419 ... (5 Replies)
Discussion started by: ntekupal
5 Replies
Login or Register to Ask a Question