replace space for enter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace space for enter
# 1  
Old 07-14-2010
replace space for enter

i have to print in a html file directories like this
Code:
/home/user
/home/user/dir

but the problem is that when i us this comand
Code:
listado=`find $direcreal -type f -print`

i get this
Code:
/home/user /home/user/dir1

i try with sed to replace the space with an enter

Code:
mostrarlistado=`echo "$listado" | sed "s/\ /\n/g"`

but i keep printing the same result

Last edited by pludi; 07-14-2010 at 04:27 PM.. Reason: code tags, please...
# 2  
Old 07-14-2010
You'll have to quote it correctly. Compare the output of
Code:
echo $mostrarlistado

to
Code:
echo "$mostrarlistado"

# 3  
Old 07-14-2010
Try it with tr instead of sed:
Code:
tr " " "\n"

# 4  
Old 07-14-2010
with tr " " "\n" i get the same result
/home/user /home/user/dir1
# 5  
Old 07-14-2010
Maybe your problem is in the actual HTML? If you're using the results straight from sed, you're probably getting something like this:

Code:
<div id="blablabla">
/home/user
/home/user/dir
</div>

And if that's the case, you're missing the <br /> tag that signals a line break in HTML. If I remember correctly, implicit line breaks like the ones above turn into spaces when HTML is rendered on to a webpage.

So, if this is your problem, try replacing the spaces with "<br />" instead of newlines.

Last edited by j_jiffer; 07-14-2010 at 05:58 PM.. Reason: typo
# 6  
Old 07-14-2010
It is like Pludi says, just do a:
Code:
echo "$listado"

# 7  
Old 07-14-2010
All right, now I got it!

Code:
find $direcreal -type f -print

This already prints file names separated/delimited by "\n", but then you assign this output to a variable, where AFAIK all "\n" get converted to a whitespace. Later you actually do the same with another variable.
Why not simply redirect the output of the find command to a file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

2. Shell Programming and Scripting

Transpose multiple rows (with a mix of space and enter) to a single column

How to change the uploaded weekly file data to the following format? New Well_Id,Old Well_Id,District,Thana,Date,Data,R.L,WellType,Lati.,Longi. BAG001,PT006,BARGUNA,AMTALI,1/2/1978,1.81,2.29,Piezometer,220825,901430 BAG001,PT006,BARGUNA,AMTALI,1/9/1978,1.87,2.29,Piezometer,220825,901430... (3 Replies)
Discussion started by: sara.nowreen
3 Replies

3. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

4. UNIX for Dummies Questions & Answers

replace %20 with space

Hi, I need torename filenames with %20 to space in a batch wise.Can anyone help me please. Need it badly Eg. English%20Brochure%20002-1 to be replace to English Brochure 002-1 Thanks a lot Please use and tags when posting code, data or logs etc. to preserve formatting... (8 Replies)
Discussion started by: umapearl
8 Replies

5. Programming

Replace one space with nothing

hi, d o g e v o l i want a perl command for the above string which should change to the below dog evol replace one space with nothing and two spaces with one space. Thanks, Amey (3 Replies)
Discussion started by: ameyrk
3 Replies

6. Shell Programming and Scripting

Replace every other space

I'd like a sed command to replace every other space in my file. File: 0 1 0 3 0 2 0 5 Want: 01 03 02 05 Does anyone have any ideas? (9 Replies)
Discussion started by: peanuts48
9 Replies

7. Shell Programming and Scripting

Replace long space to become one space?

Hi, i have the log attached. Actually i want the long space just become 1 space left like this : Rgds, (12 Replies)
Discussion started by: justbow
12 Replies

8. Shell Programming and Scripting

Pressing "Enter/Space bar" using Net::TELNET? in Perl

I'm trying to learn how to get my script to execute the enter button when it telnets into a router and the router displays output but you need to press the space bar or enter button to continue displaying my output of the router. How is this done? (0 Replies)
Discussion started by: xmaverick
0 Replies

9. Shell Programming and Scripting

Replace space

Hai masters, If a file contains content of 2000 lines, from which i need to remove the first n characters or first n spaces from each line of the file. If suppose to remove n characters or first n spaces from a single line means, just use the command nx. But from the above scenario,... (9 Replies)
Discussion started by: ecearund
9 Replies

10. Shell Programming and Scripting

replace space by _

Hi I need to know how I change the spaces by _ in folders and filder founded by find ex. find . -name "* *" -exec echo {} \; ./test space ./test space/new file.txt ./test space/new file ./test space/untitled folder ./test space/untitled folder/new fileruben ./Backup/backup/Image... (6 Replies)
Discussion started by: ruben.rodrigues
6 Replies
Login or Register to Ask a Question