read each line one at a time in csh

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question




















  • 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










  • @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














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.







share|improve this question




















  • 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










  • @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












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.







share|improve this question












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.









share|improve this question











share|improve this question




share|improve this question










asked Mar 15 at 22:51









michael morgan

182




182











  • 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










  • @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
















  • 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










  • @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















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















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay