LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 04-11-2008, 08:24 AM   #1
rajaniyer123
Member
 
Registered: Feb 2004
Location: BARODA, GUJARAT
Posts: 259

Rep: Reputation: 30
Regarding replacing characters in log file


Hi

As I have one log files of approx. 50,000 lines of same format i whcih I want to replace the line format as per given details

Existing Line

"10.49.6.64" "NULL-AUTH-USER" "01/Feb/2008:00:17:42 -0800" "GET /soap/v2008/Authentication?wsdl HTTP/1.1" 200 9567

Required Line

10.49.6.64 "NULL-AUTH-USER" [01/Feb/2008:00:17:42 -0800] "GET /soap/v2008/Authentication?wsdl HTTP/1.1" 200 9567


The brief summary is

1. In first field I want to removee double quotes of IP Address
2. In third field I want to replace the double quote with square brackets.


Can anybody give me command to do the same.

Thanks
Rajan
 
Old 04-11-2008, 08:36 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Given the string you've posted, I assume the "third field" is actually the "third and fourth fields". Then you can use awk to replace double quotes in the relevant fields:
Code:
gawk '{gsub("\"","",$1); gsub("\"","[",$3); gsub("\"","]",$4); print}' logfile
This does not modify the file in place, but you have to redirect the output to another file and eventually overwrite the original one.

Last edited by colucix; 04-11-2008 at 08:38 AM.
 
Old 04-11-2008, 08:59 AM   #3
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 540

Rep: Reputation: Disabled
Code:
awk '{print gensub("\"","","g",$1) " " $2 " " gensub("^\"","[","g",$3) " " gensub("\"$","]","g",$4) " " $5 " " $6 " " $7 " " $8 " " $9}' logfilename
Edit : congratulations to colucix faster and better solution than me

Last edited by berbae; 04-11-2008 at 09:01 AM.
 
Old 04-11-2008, 09:13 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by berbae View Post
Edit : congratulations to colucix faster and better solution than me
Thanks Just a note, berbae: when using print in awk you can separate fields with a comma (instead to explicitly put a blank space). In this way the default output field separator (that is a blank space) is used.
 
Old 04-12-2008, 11:32 AM   #5
rajaniyer123
Member
 
Registered: Feb 2004
Location: BARODA, GUJARAT
Posts: 259

Original Poster
Rep: Reputation: 30
Thanks to all

Hi

Thanks to all


It works for me.

Thanks
Rajan
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash replacing characters within a variable baks Programming 5 03-19-2007 01:33 AM
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 07:55 AM
Replacing characters in file names? yuccabrevifolia Linux - Software 1 04-19-2006 02:31 PM
replacing characters in a file with others pcdude Linux - General 6 01-19-2005 01:29 AM
wierd characters in /var/log/wtmp mindfestival Linux - Newbie 2 04-22-2004 02:02 AM


All times are GMT -5. The time now is 04:31 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration