Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 1st April 2009, 12:36 PM
Witlof Offline
Registered User
 
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6
Question Linux SED command help

Hello,

Hopefully someone can help me. I'm having troubles with splitting files. I got lots of logfiles with names like YYYYMMDD.log with the following content:

Code:
2009-03-05 07:35:11,<IP-ADDRESS>,<EMAIL-ADDRESS>,26/8-22-5-19-23,36692479174,1,1,91010507
2009-03-05 07:35:11,<IP-ADDRESS>,<EMAIL-ADDRESS>,26/8-10-9-26-5,108531796850,1,1,91010507
2009-03-05 07:35:11,<IP-ADDRESS>,<EMAIL-ADDRESS>,26/8-10-9-26-13,78524645570,1,1,91010507
2009-03-05 07:36:31,<IP-ADDRESS>,<EMAIL-ADDRESS>,27/4-23-70-9-10,82631681819,1,1,91030509
2009-03-05 07:46:32,<IP-ADDRESS>,<EMAIL-ADDRESS>,27/4-23-58-16-15,134007486202,46,17,91030509
2009-03-05 07:46:32,<IP-ADDRESS>,<EMAIL-ADDRESS>,27/4-23-70-10-9,75059663011,1,1,91030509
I need to split these logfiles into 2 logfiles. 1 with the lines containing ",26/" and the other one with containing ",27/".

For those who wants to know why I need this, It's a Distributed.net personal proxy logfile. We want to split project-stats, but it's to much work to do this by hand. So hopefully someone can help me. I know it's possible with the SED command, but don't know how to use it.
Reply With Quote
  #2  
Old 1st April 2009, 12:44 PM
Witlof Offline
Registered User
 
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6
Almost solved it, but how can I do this automatic?

Code:
sed -n '/,26\//p' <DATE>.log > 26-<DATE>.log
sed -n '/,27\//p' <DATE>.log > 27-<DATE>.log
Sorry for not using edit....

Last edited by Witlof; 1st April 2009 at 12:51 PM.
Reply With Quote
  #3  
Old 1st April 2009, 11:29 PM
Witlof Offline
Registered User
 
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6
Question almost

After a long day searching on the web, I almost got it. But it won't work on multiple files.

This command works for one file:
sed -n '/,26\//p' 20090303.log > ogr26-20090303.log

But this isn't working:
sed -n '/,26\//p' *.log > ogr26-*.log

I'm getting one big file named ogr26-*.log instead of date seperated. What am I doing wrong?
Reply With Quote
  #4  
Old 2nd April 2009, 12:34 AM
sideways's Avatar
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
sed is the wrong tool, use grep

Code:
grep ",26/" [file list] > 26.log
Code:
grep ",27/" [file list] > 27.log
Reply With Quote
  #5  
Old 2nd April 2009, 09:24 AM
Witlof Offline
Registered User
 
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6
Thanks for your reply, but grep does the same thing. I don't need the results in 1 file, but like the original seperated by day. So:

20090401.log -> lines with ",26/" -> 26-20090401.log
-> lines with ",27/" -> 27-20090401.log

20090402.log -> lines with ",26/" -> 26-20090402.log
-> lines with ",27/" -> 27-20090402.log
Reply With Quote
  #6  
Old 2nd April 2009, 04:02 PM
Witlof Offline
Registered User
 
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6
I did it \o/

Code:
for i in $( ls ); do
  sed -n '/,26\//p' $i > ogr26/$i
done
Problem solved
Reply With Quote
  #7  
Old 2nd April 2009, 04:08 PM
sideways's Avatar
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
it's still the wrong tool, and you have a Useless use of ls

Code:
for i in *; do grep ",26/" $i > ogr26/$i; done
Reply With Quote
  #8  
Old 2nd April 2009, 04:14 PM
creeping death's Avatar
creeping death Offline
Registered User
 
Join Date: Feb 2008
Posts: 655
what sideways gave should give you two files...(notice the stdout re-direction to 27.log and 26.log)

sed is a stream editor, while grep is for pattern matching...grep seems more appropriate here...but anywho...

good that you solved the problem on your own and we nice enough to share your solution.
__________________
c_d -- superfluously plenteous yet indolently otiose
Reply With Quote
  #9  
Old 2nd April 2009, 04:18 PM
sideways's Avatar
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
btw, don't run those commands in a directory containing other files, it will empty them. To be safe you should make the ls command useful with something like

Code:
for i in $(ls ogr26*); do ...
(which also qualifies for a "Useless use of ls" award, simpler is: 'for i in ogr26*; do ...' )
Reply With Quote
Reply

Tags
command, linux, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
linux command Shiva01 Using Fedora 11 22nd September 2009 09:30 PM
Linux: GUI vs. Command Line hermouche Linux Chat 19 10th December 2008 01:16 AM
ifconfig command very new to linux tidy_boy Using Fedora 4 26th April 2006 07:29 PM


Current GMT-time: 03:36 (Monday, 20-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat