The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: space problem in files
formula
Newbie
Rank: 1



UID 148
Digest Posts 0
Credits 0
Posts 24
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:49 AM  Profile | P.M. 
space problem in files



space problem in files



hi,

i have a file containing a list of entries.

want to do ls on them.

for a in `cat <list.txt>`; do ls $a; done;


now some entries contain spaces.
how do i incorporate space in $a.

quoting $a in "" doesn't help.


Top
010081
Newbie
Rank: 1



UID 28
Digest Posts 0
Credits 0
Posts 55
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:49 AM  Profile | P.M. 
are you trying to check whether files in list.txt exists? can you show list.txt?
Top
cfajohnson
Newbie
Rank: 1



UID 19
Digest Posts 0
Credits 0
Posts 63
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:50 AM  Profile | P.M. 
quote:
originally posted by vibhor_agarwali
list contains name of files:

eg.

a.txt
the hell.txt
etc.

i want to perform some operations on all.

now how do i go about with "the hell.txt"



code:
while read file
do
    echo "$file"
done < list.txt
since some of the filename contain spaces use quotes to do your operation.
Top
brynrees
Newbie
Rank: 1



UID 78
Digest Posts 0
Credits 0
Posts 26
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:50 AM  Profile | P.M. 
okay,

and if i have to take it directly from command substitution:

like:

for a in `find . -type f`; do ......
Top
MD.45
Newbie
Rank: 1



UID 259
Digest Posts 0
Credits 0
Posts 25
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:50 AM  Profile | P.M. 
quote:
originally posted by vibhor_agarwali
okay,

and if i have to take it directly from command substitution:

like:

for a in `find . -type f`; do ......

then ...



code:
find . -type f | while read file
do
Top
clvezlys
Newbie
Rank: 1



UID 92
Digest Posts 0
Credits 0
Posts 44
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 14, 2007 08:50 AM  Profile | P.M. 
great,

i generally do my work with for, not pretty convercent with while.  

any way of doing this for loop.
Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:40 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.007145 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP