Sed append text to end of line if line contains specific text? How can this be done?
I'm trying to get sed to add some text to the end of a line if that line contains a specific piece of text.
Quite simple i have a script...
And i want to use sed (i think is probably right for the job) to add text to the end of all the lines that are 'echo'
I've seen that you can :-
sed 's/$/text/' filename
But that appends to every single line i want to do something like
sed 's|echo*$|>> /var/log/output_to_log.txt|' filename
As you can see i want all the echo's to send out to a log, in the script i've already created but at the moment the echo's just send to stout, and i could run the script with filename 2>&1 /var/log/output_to_log.txt, but i'm trying to do it this other way.
This works for me:
Deleted as makyo's example:
sed -i '/echo/s|$| >> /var/log/output_to_log.txt|' filename
is more relevant and elegant.
Sweet thanks guys both ideas work great. And great website not seen that one before.. cheers
so one liner
sed -e " /^http/s|$|\'| " -e "s/^http/\'http/"
sed -e " /^http/s|$|\'| ; s/^http/\'http/"
err to one liner ( better ) without two -e please
|All times are GMT -5. The time now is 08:36 AM.|