LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-25-2011, 11:00 PM   #1
sunilsagar
Member
 
Registered: Jul 2011
Posts: 30

Rep: Reputation: Disabled
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.
 
Old 07-26-2011, 01:14 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Code:
sed 's/%u/& %D/'
 
1 members found this post helpful.
Old 07-26-2011, 01:28 AM   #3
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 158

Rep: Reputation: 44
sed -i '/^LogFormat/s/%u/& %D/' file

You can use perl in-line editing too in a similar way.
 
Old 07-26-2011, 01:44 AM   #4
sunilsagar
Member
 
Registered: Jul 2011
Posts: 30

Original Poster
Rep: Reputation: Disabled
thanks it worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Insert line using sed or awk at line using line number as variable sunilsagar Programming 11 02-03-2012 10:48 AM
sed insert newline character jhwilliams Linux - Software 6 06-08-2007 03:13 PM
Insert character by using sed/awk manish_meet_in Linux - General 3 04-05-2007 12:19 PM
Insert after every nth character using sed DoDo1975 Linux - Software 2 01-17-2007 06:59 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration