LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   insert a character in line using sed/awk (https://www.linuxquestions.org/questions/programming-9/insert-a-character-in-line-using-sed-awk-893751/)

sunilsagar 07-25-2011 11:00 PM

insert a character in line using sed/awk
 
Hello !

I have a string as below

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

Want the above string to be modified as

LogFormat "%h %l %u %D %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

inserting %D after %u in the string

Please suggest.

crts 07-26-2011 01:14 AM

Code:

sed 's/%u/& %D/'

A.Thyssen 07-26-2011 01:28 AM

sed -i '/^LogFormat/s/%u/& %D/' file

You can use perl in-line editing too in a similar way.

sunilsagar 07-26-2011 01:44 AM

thanks it worked.


All times are GMT -5. The time now is 10:06 AM.