Results 1 to 3 of 3
I have a text file(replicateTotals.txt) with a bunch of lines in this form:
Code:
2009/10/21-12:15:58 avtar Stats <6559>: 111.5 KB in 1,838 messages sent to server, 4.541 MB in 1,832 ...
- 10-22-2009 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 11
Extracting Substring with SED
I have a text file(replicateTotals.txt) with a bunch of lines in this form:
What I would like to do is extract just the data amount which appears right after the '<6559>'. So, the output I would want from the lines above would be:Code:2009/10/21-12:15:58 avtar Stats <6559>: 111.5 KB in 1,838 messages sent to server, 4.541 MB in 1,832 messages received from server. 2009/10/21-19:44:40 avtar Stats <6559>: 22.88 GB in 2,781,764 messages sent to server, 157.2 MB in 2,779,968 messages received from server. 2009/10/21-19:44:40 avtar Stats <6559>: 72.55 MB in 1,338,246 messages sent to server, 22.80 GB in 1,336,448 messages received from server.
I'm not very experienced with sed, but here's the command that I came up with to grab this data:Code:111.5 KB 22.88 GB 72.55 MB
This command is not working. Can anyone tell me where I'm going wrong?Code:# cat replicateTotals.txt | grep \<6559\> | sed 's/.*\<6559\>\: \([[:digit:]]*\.[[:digit:]]*(KB|MB|GB)\).*/\1/'
- 10-22-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Several problems:Code:grep '<6559>' replicateTotals.txt | sed -r 's/.*<6559>: ([[:digit:]]*.[[:digit:]]* (KB|MB|GB)).*/\1/'
When you have a string within single quotes you don't have to escape characters. They \'s were being searched for as part of the string.
You were missing a space between [[:digit:]]*.[[:digit:]]* and (KB|MB|GB).
Use of (KB|MB|GB) requires extended regular expressions so you have to use the -r option.
- 10-22-2009 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 11
You rock!!
Thanks, man.


Reply With Quote