Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Question
In linux, you have a file called test.txt, how do you replace only the first occurence of "GNU", on each line in that file, with "NGU"? You can have this output just go to prompt/stdout (no need to capture it in new file).
Answer
sed -e 's/GNU/NGU/' test.txt
^^ note the -e is needed (e for expression)
^^ note that the last / in the 's/regex/replace/' is not followed by anything, i.e. not followed by g, to indicate replacing only the first instance found, not all instances

Question
In linux, you have a file called test.txt, how do you replace only the first occurence of "GNU", on each line in that file, with "NGU"? You can have this output just go to prompt/stdout (no need to capture it in new file).
Answer
?

Question
In linux, you have a file called test.txt, how do you replace only the first occurence of "GNU", on each line in that file, with "NGU"? You can have this output just go to prompt/stdout (no need to capture it in new file).
Answer
sed -e 's/GNU/NGU/' test.txt
^^ note the -e is needed (e for expression)
^^ note that the last / in the 's/regex/replace/' is not followed by anything, i.e. not followed by g, to indicate replacing only the first instance found, not all instances
If you want to change selection, open document below and click on "Move attachment"

8. Streams and sed -- The Stream Editor
\ > <resultfile> where <search-regexp> is a regular expression, <replace-text> is the text you would like to replace each occurrence with, and <option> is nothing or <span>g , which means to replace every occurrence in the same line (usually sed just replaces the first occurrence of the regular expression in each line). (There are other <option> ; see

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.