Reputation: 17785
I am looking at access logs which have plenty entries such as:
localhost_access_log.2012-05-07.txt:129.223.57.10 - - [07/May/2012:00:02:11 +0000] 2434 "POST /maker/www/jsp/opp/OpportunityForm.do HTTP/1.1" 302 - "https://dm2.myjones.com/maker/www/jsp/opp/Opportunity.jsp?screenDisplay={0}&forecastIcon={1}" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; MS-RTC LM 8)"
the number after the datetime stamp is the execution time and the string in quotes is the URL.
I wish to just sed, the URL and the response time and have them in the format
URL, response time
e.g.
POST /maker/www/jsp/opp/OpportunityForm.do HTTP/1.1, 2434
Upvotes: 1
Views: 1436
Reputation: 360105
sed
:
sed 's/^[^]]\+\] \([[:digit:]]\+\) \("[^"]\+"\).*/\2,\1/' inputfile
Perl:
perl -lne 'print "$2,$1" if /.*? (\d+) (".*?")/'
Upvotes: 2
Reputation: 8948
You can use awk
to print 6th, 7th, 8th and 9th entries like this:
awk '{print $7, $8, $9, ", " $6}' <access_log>
Output: "POST /maker/www/jsp/opp/OpportunityForm.do HTTP/1.1" , 2434
awk
by default separates fields by space. nth
gets stored in $n
. So in your input line:
$7: "POST
$8: /maker/www/jsp/opp/OpportunityForm.do
$9: HTTP/1.1"
$6: 2434
Upvotes: 1