LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-14-2010, 08:08 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Replace values in log file


Hi,

I have the following values in my log file:

...
2010-05-13 11:00:00 k_TRANSFER OK (11)
2010-05-13 11:30:01 m_TRANSFER OK (21)
2010-05-13 12:00:00 k_TRANSFER OK (12)
2010-05-13 12:30:00 m_TRANSFER OK (32)
2010-05-13 13:00:00 m_TRANSFER OK (13)
...

I want to replace every number with it's decrement. For example, the above values should be:

...
2010-05-13 11:00:00 k_TRANSFER OK (10)
2010-05-13 11:30:01 m_TRANSFER OK (20)
2010-05-13 12:00:00 k_TRANSFER OK (11)
2010-05-13 12:30:00 m_TRANSFER OK (31)
2010-05-13 13:00:00 m_TRANSFER OK (12)
...


Thanks
 
Old 05-14-2010, 08:10 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
Sounds like a plan. What have you tried? Where are you stuck?
 
Old 05-14-2010, 08:16 AM   #3
laki47
Member
 
Registered: Feb 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by grail View Post
Sounds like a plan. What have you tried? Where are you stuck?
I tried to replace manually
 
Old 05-14-2010, 08:39 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
perl -ne '{m/\((\d+?)\)/; my $x=$1; --$x; s/\($1\)/($x)/; print}' <filename>

Last edited by PMP; 05-14-2010 at 08:42 AM. Reason: added match for digits
 
Old 05-14-2010, 08:44 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,223

Rep: Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019Reputation: 1019
What's the point of a log file if you're going to "fiddle" the data ...
Dangerous precedent that.
 
Old 05-14-2010, 09:41 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
I agree with syg00 about the dangers, but you could use this too:
Code:
awk '{x=gensub(/.*\(([0-9]+)\)/,"\\1","g");sub(x,x-1,$NF)}1' log
 
  


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
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
setting file permissions for file /var/log/Xorg.0.log mfb Linux - Security 1 07-07-2009 01:41 PM
How to replace default Mandrake log-in screen with one in KDE? iliks Mandriva 2 06-30-2004 06:09 AM
dublicate values in file topche Programming 10 07-09-2003 04:44 AM
how to replace IP address with user login id in squid's access log x2000koh Linux - Networking 1 08-20-2002 02:08 PM


All times are GMT -5. The time now is 02:14 AM.

Main Menu
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