LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to handle file names with spaces in them (https://www.linuxquestions.org/questions/programming-9/how-to-handle-file-names-with-spaces-in-them-304875/)

bahadur 03-22-2005 06:55 PM

how to handle file names with spaces in them
 
NOTICE: This task has to be done without using the command find.

now here is the problem. analyze the output of the following two commands

[jnsahibz@charlie jnsahibz]$ ls -l |awk '/^d/ {print $9}'
CV
Desktop
Favorites
My
assignment
bin
mail
public_html
zakir

[jnsahibz@charlie jnsahibz]$ ls -l
total 5762
drwx------ 2 jnsahibz mc00 512 Mar 14 16:15 CV
drwxr-xr-x 2 jnsahibz mc00 512 Mar 20 22:27 Desktop
drwx------ 3 jnsahibz mc00 512 Feb 17 11:28 Favorites
drwx------ 3 jnsahibz mc00 512 Mar 5 18:14 My Documents
drwx------ 2 jnsahibz mc00 512 Mar 22 16:47 assignment
drwxr-xr-x 3 jnsahibz mc00 512 Mar 22 15:05 bin
-rw------- 1 jnsahibz mc00 2931431 Mar 19 17:21 junaid.zip
drwx------ 2 jnsahibz mc00 512 Mar 19 19:59 mail
drwxr-xr-x 4 jnsahibz mc00 512 Mar 21 19:41 public_html
drwx------ 3 jnsahibz mc00 512 Mar 13 18:45 zakir naik


when i do a simple ls -l it gives me a correct directory name even if it is with spaces. like the directory name My Documents.

but when i try to pipe the damn thing into another command , the other command only picks up the My part of it and leaves the other.

so whats the way out?

Nis 03-22-2005 07:10 PM

Try putting the $9 in quotes like below:
Code:

ls -l |awk '/^d/ {print "$9"}'

cylix 03-22-2005 07:45 PM

Because awk is breaking up the elements based on space.

$10 is going to be the next half.

Since awk doesn't catch the whitespace, you'll have to do something different..

I did: ls -1p |awk '/\// {print }

bahadur 03-23-2005 05:15 AM

buddy this is not working can you plz explain ur code a little


All times are GMT -5. The time now is 05:34 PM.