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

1st April 2009, 12:36 PM
|
|
Registered User
|
|
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6

|
|
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.
|

1st April 2009, 12:44 PM
|
|
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.
|

1st April 2009, 11:29 PM
|
|
Registered User
|
|
Join Date: Jan 2009
Location: Veldhoven, The Netherlands
Posts: 6

|
|
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?
|

2nd April 2009, 12:34 AM
|
 |
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
|

2nd April 2009, 09:24 AM
|
|
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
|

2nd April 2009, 04:02 PM
|
|
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
|

2nd April 2009, 04:08 PM
|
 |
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
|

2nd April 2009, 04:14 PM
|
 |
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
|

2nd April 2009, 04:18 PM
|
 |
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 ...'  )
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 03:36 (Monday, 20-05-2013)
|
|
 |
 |
 |
 |
|
|