 |
|
 |
|
Next: Truecrypt
|
| Author |
Message |
External

Since: Dec 10, 2003 Posts: 974
|
(Msg. 1) Posted: Wed Feb 06, 2008 4:59 pm
Post subject: using cat to get a list to for in sh or in ksh Archived from groups: comp>sys>mac>programmer>misc (more info?)
|
|
|
In sh and ksh, I have used
for i in `cat file`
do
do-something-with-$i
done
on other systems with no problem. In OS X, this sometimes hangs, but
sometimes it doesn't, which is very confusing. Pr also hangs, but for
some strange reason, head works in the same script!
Does anybody have any idea what I am doing wrong? This should always
work fine, but sometimes it doesn't.
--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office] >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
External

Since: Dec 10, 2003 Posts: 974
|
(Msg. 2) Posted: Wed Feb 06, 2008 4:59 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <bob-A81B29.15162506022008.RemoveThis@news.verizon.net>,
Robert Peirce <bob.RemoveThis@peirce-family.com.invalid> wrote:
> In sh and ksh, I have used
>
> for i in `cat file`
> do
> do-something-with-$i
> done
>
> on other systems with no problem. In OS X, this sometimes hangs, but
> sometimes it doesn't, which is very confusing. Pr also hangs, but for
> some strange reason, head works in the same script!
>
> Does anybody have any idea what I am doing wrong? This should always
> work fine, but sometimes it doesn't.
Okay. I have more info. There seems to be some sort of buffer
limitation in for. Perhaps somebody can tell me what it is. The file,
in the case that hangs, is 1,635,888 lines and 24,538,320 characters.
Other platforms seem to be able to handle this. OS X is hanging.
--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office] >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
External

Since: Dec 10, 2003 Posts: 974
|
(Msg. 3) Posted: Wed Feb 06, 2008 4:59 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <bob-AA757D.15320506022008 RemoveThis @news.verizon.net>,
Robert Peirce <bob RemoveThis @peirce-family.com.invalid> wrote:
> In article <bob-A81B29.15162506022008 RemoveThis @news.verizon.net>,
> Robert Peirce <bob RemoveThis @peirce-family.com.invalid> wrote:
>
> > In sh and ksh, I have used
> >
> > for i in `cat file`
> > do
> > do-something-with-$i
> > done
> >
> > on other systems with no problem. In OS X, this sometimes hangs, but
> > sometimes it doesn't, which is very confusing. Pr also hangs, but for
> > some strange reason, head works in the same script!
> >
> > Does anybody have any idea what I am doing wrong? This should always
> > work fine, but sometimes it doesn't.
>
> Okay. I have more info. There seems to be some sort of buffer
> limitation in for. Perhaps somebody can tell me what it is. The file,
> in the case that hangs, is 1,635,888 lines and 24,538,320 characters.
> Other platforms seem to be able to handle this. OS X is hanging.
This is embarrassing (for OS X), but I ran this script using ksh in Uwin
on a PC and it worked:
for i in $(cat s.p); do print $i; done | head
but it doesn't work in ksh on OS X.
Cat works fine by itself, so the limitation is in the for;do;done loop.
--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office] >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
External

Since: Nov 28, 2006 Posts: 3
|
(Msg. 4) Posted: Wed Feb 06, 2008 8:09 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Robert Peirce <bob.DeleteThis@peirce-family.com.invalid> writes:
>In sh and ksh, I have used
> for i in `cat file`
> do
> do-something-with-$i
> done
>on other systems with no problem. In OS X, this sometimes hangs, but
>sometimes it doesn't, which is very confusing. Pr also hangs, but for
>some strange reason, head works in the same script!
Reading the whole file into one line exceeds the shell's line length
limit.
It works on other systems because they have longer line-length limits.
It's still a bad idea.
head(1) works because it's not reading the whole file.
The ksh(1) input mechanism is the read builtin, not cat(1). RTFM
ksh(1).
--
dhs spencer.DeleteThis@panix.com >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
External

Since: Jan 13, 2005 Posts: 927
|
(Msg. 5) Posted: Wed Feb 06, 2008 11:01 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <bob-A81B29.15162506022008 DeleteThis @news.verizon.net>,
Robert Peirce <bob DeleteThis @peirce-family.com.invalid> wrote:
> In sh and ksh, I have used
>
> for i in `cat file`
> do
> do-something-with-$i
> done
>
> on other systems with no problem. In OS X, this sometimes hangs, but
> sometimes it doesn't, which is very confusing. Pr also hangs, but for
> some strange reason, head works in the same script!
>
> Does anybody have any idea what I am doing wrong? This should always
> work fine, but sometimes it doesn't.
May I suggest
while read line
do
do-something-with-$line
done <file
This will do something similar, assuming there is one item per
line.
if you have multiple fixed items per line you can do
while read item1 item2 item3
do
do-something-with-$item1
do-something-with-$item2
do-something-with-$item3
done <file
Or if you do not know how may items are on each line you can try
while read line
do
set -- $line
for item
do
do-something-with-$item
done
done <file
Bob Harris >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
External

Since: Nov 28, 2006 Posts: 3
|
(Msg. 6) Posted: Wed Feb 06, 2008 11:01 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Dec 10, 2003 Posts: 974
|
(Msg. 7) Posted: Wed Feb 06, 2008 11:01 pm
Post subject: Re: using cat to get a list to for in sh or in ksh [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
In article <fodebg$c4t$1@reader2.panix.com>,
David Spencer <spencer DeleteThis @panix.com> wrote:
> Robert Peirce <bob DeleteThis @peirce-family.com.invalid> writes:
>
> >In sh and ksh, I have used
>
> > for i in `cat file`
> > do
> > do-something-with-$i
> > done
>
> >on other systems with no problem. In OS X, this sometimes hangs, but
> >sometimes it doesn't, which is very confusing. Pr also hangs, but for
> >some strange reason, head works in the same script!
>
> Reading the whole file into one line exceeds the shell's line length
> limit.
>
> It works on other systems because they have longer line-length limits.
> It's still a bad idea.
>
> head(1) works because it's not reading the whole file.
>
> The ksh(1) input mechanism is the read builtin, not cat(1). RTFM
> ksh(1).
I am familiar with read and I have used it in more recent scripts. This
is an old one I thought would work and it didn't. As a stopgap, I used
split to break it into smaller files that I could read with cat until I
get around to using read.
--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office] >> Stay informed about: using cat to get a list to for in sh or in ksh |
|
| Back to top |
|
 |  |
| Related Topics: | Image list - Hi all, I'm developing a simple application with Project Builder using Carbon (nib based). I'd like to create a list of pictures (like tumbnails view) and I'm trying to use the Browser Control but I'm not sure this is the correct choice. Some one can..
Can't add application to Limitations list - When adding limitations to a user account by granting access to only specific applications, our application does not remained checked. You can add a check in the checkbox next to the application name, but the value is not retained and the application is....
Apple event : How to add base64 data type param to the lis.. - Hi All, Has anyone successfully worked with XMLRPC AE object with base64 params? I am making a XML-RPC call using Apple Events on Mac OSX. I use AEPutPtr to add params to my paramlist which I create using AECreateList(..). I am able to successfully ad...
modify OS X keyboard mappings - Hello, I need to have access to the french characters. I can do this with the Canadian - CSA keyboard. However, that keyboard has a "," as a decimal. I need a ".". Changing it in the international control panel does not change...
Shared memory - Hello all, If you're not on the beach maybe you can give me a little help. I need to implement shared memory between my application and a helper tool. At first I tried CFMessageProts. This works, but if you transport huge amounts of data the data get al... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|