Here is a script that prints the text of the full line that 'word' was on after 'word' is removed, selecting all occurences of 'word':
sed -ne 's/word//p' file.txt >> newfile.txt
How can I print only text of the line after the first occurence of 'word', and remove 'word' of the printed line?
I am using OSX.
Here is a sample text:
Blalala 'Omfoem From balanf word I want this output word Not this output Omfoem527
Here is the output I expect:
I want this output
UPDATE: Here is the script I have, which does what I need:
sed -n 's/^.*word //p' file.txt > temp.txt sed -n '1p' temp.txt >> newfile.txt rm temp.txt
First line prints the text of the full line that 'word' was on after 'word' is removed, selecting all occurences of 'word' in the file temp.txt. I have also added ^.* in case there is any other text before 'word'.
Second line prints only the first line of the file temp.txt into newfile.txt Third line removes temp.txt file.
Might not be the most efficient but it works.