want to add a word in front if found another word
hi,
I want to add a word in front if found the word i want : eg RewriteCond if found the RewriteCond then add ###TEST### I still want to keep the RewriteCond word ###TEST###RewriteCond how to do this using SED ? Please help thank you. |
Just substitute "RewriteCond" with "###TEST###RewriteCond":
Code:
sed 's/RewriteCond/###TEST###RewriteCond/g' file |
Hi,
Welcome to LQ! Sounds like homework to me. Please read the LQ Rules. 'Rute Tutorial & Exposition' 'Linux Documentation Project' 'LinuxSelfHelp' The above links are just a few good references that can be used by a newbie to enhance their endeavor with GNU/Linux. These links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! |
Hi Sir,
Sorry i think i ask wrongly, I rephase my question : If i want to insert ####TEST#### below the ####HAPPY#### after found the word ####HAPPY#### is it possible? eg ####HAPPY#### ####TEST####RewriteCond ####TEST####RewriteRule ####TEST####Rewrite ####TEST####Rewrite Sorry to disturb you all :) |
OK, if you had read the tutorial presented by colucix, you would have found your answer. Perhaps you can read just the pertinent part.
HTH Forrest |
appreciate that you can give one example as i don't really understand the tutorial mean.
Thank you in advance. |
From the tutorial:
Quote:
Starting with the first line (specified by the 1) and continuing until "the pattern 'start' is found" (specified by the /start/) perform the substitution of replacing "#" followed by "any number of" (specifed by the *) "any character" (specified by the ".") with nothing (specified by the emptyness between the second / and the last / in the substitution command). I'll leave decoding the second expression as an exercise for you. For your homework, you may also need to know that '^' matches the beginning of a line. Forrest |
cool;
You need to tell us WHAT you don't understand!!! forrestt has given you a link to the addressing feature of SED. The general construct is to first specify an "address range" and then operate within that range. Example: sed '/brown/,/car/s/dog/cat/' filename Translation: Start with the first line containing "brown", and end with the first line containing "car". In this range, replace the first occurrence on each line of "dog" with "cat" |
To all,
Thank you for the explaination, i will try to figure out and apply to the script. Thank you :) |
All times are GMT -5. The time now is 01:39 PM. |