read each line one at a time in csh
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
In bash, code like this will read each line in a file one at a time:
while IFS=$'r' read -r line || [[ -n "$line" ]]; do
something
done < "to-read-file"
When the code is running, as long as it hasn't reached the final line of the to-read-file, I can add lines to the end of the to-read-file and the code will continue working on new added lines.
I need your help for a similar code in csh. Currently the code I am using under csh is like this:
foreach line (cat to-read-file)
(do things)
end
It will read all the lines at once. Once the code is running, the new lines added to the to-read-file will not be read. Any idea how I can make it read the line once at a time? For some reason I have to work under csh for this case.
Thank you very much.
shell-script csh
add a comment |Â
up vote
0
down vote
favorite
In bash, code like this will read each line in a file one at a time:
while IFS=$'r' read -r line || [[ -n "$line" ]]; do
something
done < "to-read-file"
When the code is running, as long as it hasn't reached the final line of the to-read-file, I can add lines to the end of the to-read-file and the code will continue working on new added lines.
I need your help for a similar code in csh. Currently the code I am using under csh is like this:
foreach line (cat to-read-file)
(do things)
end
It will read all the lines at once. Once the code is running, the new lines added to the to-read-file will not be read. Any idea how I can make it read the line once at a time? For some reason I have to work under csh for this case.
Thank you very much.
shell-script csh
csh
doesn't have aread
built-in, or anything similar. BTW, assuming you meantforeach line (`cat to-read-file`)
(with backticks), thecat
is executed only once to construct the list of words for theforeach
, it exits as soon as it finishes reading the file.csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).
â cas
Mar 16 at 1:26
btw, the shread
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, usetail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language likeawk
orsed
orperl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).
â cas
Mar 16 at 1:34
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to useawk
orsed
orperl
as you suggested to read in lines one at a time in a csh script?
â michael morgan
Mar 16 at 20:31
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In bash, code like this will read each line in a file one at a time:
while IFS=$'r' read -r line || [[ -n "$line" ]]; do
something
done < "to-read-file"
When the code is running, as long as it hasn't reached the final line of the to-read-file, I can add lines to the end of the to-read-file and the code will continue working on new added lines.
I need your help for a similar code in csh. Currently the code I am using under csh is like this:
foreach line (cat to-read-file)
(do things)
end
It will read all the lines at once. Once the code is running, the new lines added to the to-read-file will not be read. Any idea how I can make it read the line once at a time? For some reason I have to work under csh for this case.
Thank you very much.
shell-script csh
In bash, code like this will read each line in a file one at a time:
while IFS=$'r' read -r line || [[ -n "$line" ]]; do
something
done < "to-read-file"
When the code is running, as long as it hasn't reached the final line of the to-read-file, I can add lines to the end of the to-read-file and the code will continue working on new added lines.
I need your help for a similar code in csh. Currently the code I am using under csh is like this:
foreach line (cat to-read-file)
(do things)
end
It will read all the lines at once. Once the code is running, the new lines added to the to-read-file will not be read. Any idea how I can make it read the line once at a time? For some reason I have to work under csh for this case.
Thank you very much.
shell-script csh
asked Mar 15 at 22:51
michael morgan
182
182
csh
doesn't have aread
built-in, or anything similar. BTW, assuming you meantforeach line (`cat to-read-file`)
(with backticks), thecat
is executed only once to construct the list of words for theforeach
, it exits as soon as it finishes reading the file.csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).
â cas
Mar 16 at 1:26
btw, the shread
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, usetail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language likeawk
orsed
orperl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).
â cas
Mar 16 at 1:34
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to useawk
orsed
orperl
as you suggested to read in lines one at a time in a csh script?
â michael morgan
Mar 16 at 20:31
add a comment |Â
csh
doesn't have aread
built-in, or anything similar. BTW, assuming you meantforeach line (`cat to-read-file`)
(with backticks), thecat
is executed only once to construct the list of words for theforeach
, it exits as soon as it finishes reading the file.csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).
â cas
Mar 16 at 1:26
btw, the shread
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, usetail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language likeawk
orsed
orperl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).
â cas
Mar 16 at 1:34
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to useawk
orsed
orperl
as you suggested to read in lines one at a time in a csh script?
â michael morgan
Mar 16 at 20:31
csh
doesn't have a read
built-in, or anything similar. BTW, assuming you meant foreach line (`cat to-read-file`)
(with backticks), the cat
is executed only once to construct the list of words for the foreach
, it exits as soon as it finishes reading the file. csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).â cas
Mar 16 at 1:26
csh
doesn't have a read
built-in, or anything similar. BTW, assuming you meant foreach line (`cat to-read-file`)
(with backticks), the cat
is executed only once to construct the list of words for the foreach
, it exits as soon as it finishes reading the file. csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).â cas
Mar 16 at 1:26
btw, the sh
read
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, use tail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language like awk
or sed
or perl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).â cas
Mar 16 at 1:34
btw, the sh
read
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, use tail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language like awk
or sed
or perl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).â cas
Mar 16 at 1:34
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to use
awk
or sed
or perl
as you suggested to read in lines one at a time in a csh script?â michael morgan
Mar 16 at 20:31
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to use
awk
or sed
or perl
as you suggested to read in lines one at a time in a csh script?â michael morgan
Mar 16 at 20:31
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f430509%2fread-each-line-one-at-a-time-in-csh%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
csh
doesn't have aread
built-in, or anything similar. BTW, assuming you meantforeach line (`cat to-read-file`)
(with backticks), thecat
is executed only once to construct the list of words for theforeach
, it exits as soon as it finishes reading the file.csh
has many flaws and is not suitable for scripting - it's not even a good interactive shell (it had some good features for its time when it was first release in 1978, but bourne shells have long since surpassed them).â cas
Mar 16 at 1:26
btw, the sh
read
loop will also terminate when it reaches EOF but it's not so obvious because it's reading the file one line at a time. Also BTW, relying on this is introducing a deliberate race-condition to your code - if you want to continuously read a file as it is growing, usetail -f
in either a pipe or a process substitution. Finally, if you don't want to switch to a bourne shell, use a language likeawk
orsed
orperl
to process your file (I'd recommend this in sh too because while sh is capable of doing this, it's a very slow and inefficient tool for the job).â cas
Mar 16 at 1:34
@cas thank you very much. As I said I have to deal with csh in this case. Can you instruct me how to use
awk
orsed
orperl
as you suggested to read in lines one at a time in a csh script?â michael morgan
Mar 16 at 20:31