I am updating a C shell script that uses a sed command:
sed '/EOF/r $thingToAdd' $fileToAddItTo > $newFileOutput
I can’t seem to find what the /r command means or does. I think it is for a find and replace (similar to /s..../g).
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ris used to read a file and append it at the current point.The point in your example is the address
/EOF/which means this script will find the line containingEOFand then append the file specified by$thingToAddafter that point. Then it will process the rest of the file.In other words:
You can see this in action in the following transcript:
And, in response to the question in your comment about whether it will do this for every line containing the
EOFstring, yes it will:And, it will do it for every line containing the
EOFstring. Normally you would restrict something like this to lines containing only theEOFstring since that’s usually how it’s set up (with theEOFbeing the only contents of that line). You could do that simply by changing the address to/^EOF$/(the^and$are the start-of-line and end-of-line anchors respectively).Otherwise it would pick up lines you might not expect, like those containing
HEREOF,WRITEOFForNEOFACISM.