[GLLUG] why doesn't this work?

Mike Rambo mrambo at lsd.k12.mi.us
Thu Oct 23 21:15:58 EDT 2003


On Thu, 2003-10-23 at 15:11, Jeffrey Utter wrote:
> Well it works for me.  I tested it.
> 
> $ ls -l | awk {'print $9'} 
> 
> file1
> file2
> file3
> $ for TARGET in `ls -l | awk {'print $9'}`;
> > do cat $TARGET >> OUPUT;
> > done;
> $ more OUPUT
> file 1
> file 2
> file 3
> 
> 
> I would ask a few questions such as, are you doing this in a script?
> if yes, where is the script in relation to the files you are combining?
> 
> so more info is needed on your situation i think..
> 

I'm was trying to do this as a one liner from the CLI. The .mysql files
contain the mysql command text to create various tables in a database. I
wanted to push the contents of all the individual files into one big
file so that all the tables would be created in one shot. I was working
in my home directory where I had full permissions and ownership of all
the files. I had no problem listing the files or even echoing the file
names into another file but received the error when I tried to cat the
contents of the files into another file (if you follow).

For example, this works...

[mrambo at penguin mysql]$ for TARGET in `ls | awk {'print $9'}`; do echo
"processing "$TARGET; echo $TARGET >> file ; done;
processing building.mysql
processing dept.mysql
processing equipment.mysql
processing guest.mysql
processing inventory.mysql
processing itech.mysql
processing itstaff.mysql
processing makeAll.mysql
processing partused.mysql
processing repair.mysql
processing vardat.mysql
[mrambo at penguin mysql]$ ls
total 52
-rw-rw-r--    1 mrambo   mrambo        838 Jan  1  2003 building.mysql
-rw-rw-r--    1 mrambo   mrambo        221 Jan  1  2003 dept.mysql
-rw-rw-r--    1 mrambo   mrambo        532 Jan  1  2003 equipment.mysql
-rw-rw-r--    1 mrambo   mrambo        261 Oct 23 16:08 file
-rw-rw-r--    1 mrambo   mrambo        707 Oct  2 15:56 guest.mysql
-rw-rw-r--    1 mrambo   mrambo        493 Apr 18  2003 inventory.mysql
-rw-rw-r--    1 mrambo   mrambo       1016 Oct 15 14:06 itech.mysql
-rw-rw-r--    1 mrambo   mrambo        451 Jun 27 14:24 itstaff.mysql
-rw-rw-r--    1 mrambo   mrambo       5781 Oct 23 14:02 makeAll.mysql
-rw-rw-r--    1 mrambo   mrambo        414 Jun  8 21:21 partused.mysql
-rw-rw-r--    1 mrambo   mrambo       1149 Jan  1  2003 repair.mysql
-rw-rw-r--    1 mrambo   mrambo        347 Jan  1  2003 vardat.mysql
[mrambo at penguin mysql]$ cat file
building.mysql
dept.mysql
equipment.mysql
guest.mysql
inventory.mysql
itech.mysql
itstaff.mysql
makeAll.mysql
partused.mysql
repair.mysql
vardat.mysql

But this doesn't... (I'd expect this to display to screen)

[mrambo at penguin mysql]$ for TARGET in `ls | awk {'print $9'}`; do echo
"processing "$TARGET; cat $TARGET ; done;
processing building.mysql
cat: building.mysql: No such file or directory
processing dept.mysql
cat: dept.mysql: No such file or directory
processing equipment.mysql
cat: equipment.mysql: No such file or directory
processing file
cat: file: No such file or directory
processing guest.mysql
cat: guest.mysql: No such file or directory
processing inventory.mysql
cat: inventory.mysql: No such file or directory
processing itech.mysql
cat: itech.mysql: No such file or directory
processing itstaff.mysql
cat: itstaff.mysql: No such file or directory
processing makeAll.mysql
cat: makeAll.mysql: No such file or directory
processing partused.mysql
cat: partused.mysql: No such file or directory
processing repair.mysql
cat: repair.mysql: No such file or directory
processing vardat.mysql
cat: vardat.mysql: No such file or directory

Nor does it work to redirect to a file with...

[mrambo at penguin mysql]$ for TARGET in `ls | awk {'print $9'}`; do echo
"processing "$TARGET; cat $TARGET >> file2 ; done;
processing building.mysql
cat: building.mysql: No such file or directory
processing dept.mysql
cat: dept.mysql: No such file or directory
processing equipment.mysql
cat: equipment.mysql: No such file or directory
processing file
cat: file: No such file or directory
processing guest.mysql
cat: guest.mysql: No such file or directory
processing inventory.mysql
cat: inventory.mysql: No such file or directory
processing itech.mysql
cat: itech.mysql: No such file or directory
processing itstaff.mysql
cat: itstaff.mysql: No such file or directory
processing makeAll.mysql
cat: makeAll.mysql: No such file or directory
processing partused.mysql
cat: partused.mysql: No such file or directory
processing repair.mysql
cat: repair.mysql: No such file or directory
processing vardat.mysql
cat: vardat.mysql: No such file or directory

Confused...

> On Thu, Oct 23, 2003 at 01:54:27PM -0400, Mike Rambo wrote:
> > I'm trying to combine the text of all files in a directory into one
> > large file with the one liner:
> > 
> > for TARGET in `ls | awk {'print $9'}`; do cat $TARGET >> makeAll.mysql;
> > done;
> > 
> > but all I get is:
> > 
> > cat: building.mysql: No such file or directory
> > cat: dept.mysql: No such file or directory
> > cat: equipment.mysql: No such file or directory
> > cat: guest.mysql: No such file or directory
> > cat: inventory.mysql: No such file or directory
> > cat: itech.mysql: No such file or directory
> > cat: itstaff.mysql: No such file or directory
> > cat: partused.mysql: No such file or directory
> > cat: repair.mysql: No such file or directory
> > cat: vardat.mysql: No such file or directory
> > 
> > The $TARGET variable clearly contains all the filenames in the directory
> > but the cat command for some reason can't find them in this context.
> > What have I missed?
> > 
> > I know that I can do the same thing one file at a time (and probably
> > will shortly) but I'd sure like to know why this doesn't work.
> > 
> > Thanks.
> > 
> > 

-- 
Mike Rambo
mrambo at lsd.k12.mi.us

NOTE: In order to control energy costs the light at the end 
of the tunnel has been shut off until further notice...



More information about the linux-user mailing list