LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-22-2005, 07:55 PM   #1
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Rep: Reputation: 15
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?
 
Old 03-22-2005, 08:10 PM   #2
Nis
Member
 
Registered: Jul 2003
Location: Virginia
Distribution: Ubuntu Hoary (5.04)
Posts: 550

Rep: Reputation: 31
Try putting the $9 in quotes like below:
Code:
ls -l |awk '/^d/ {print "$9"}'
 
Old 03-22-2005, 08:45 PM   #3
cylix
Member
 
Registered: Dec 2004
Location: Ohio
Distribution: Fedora Core 3
Posts: 125

Rep: Reputation: 15
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 }
 
Old 03-23-2005, 06:15 AM   #4
bahadur
Member
 
Registered: Apr 2004
Distribution: Linux Red Hat
Posts: 141

Original Poster
Rep: Reputation: 15
buddy this is not working can you plz explain ur code a little
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to handle file names with spaces in them bahadur Programming 14 04-04-2005 01:04 PM
du or wc and file names with spaces bramadams Slackware 2 01-27-2005 12:43 PM
Spaces in file names JohnKFT Slackware 3 11-09-2004 04:44 PM
Bash crashes ? File names with () and spaces Danodare Slackware 1 02-27-2004 03:50 PM
File/Direcory Names with Spaces ar1 Linux - General 3 01-15-2004 11:41 AM


All times are GMT -5. The time now is 12:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration