I have a historical set of log files, that have the source IP at the end, rather than at the beginning. Due the the user agents being a string that can contain any character (spaces tabs, anything) , there is no set field count for the last field. I came up with the following shell script to convert them, but it is painfully slow, and thought converting it to perl might make it faster, but I'm stuck as all the examples in perl I've found expect a known number of fields.
while read line
do
SOURCEIP=`echo $line| sed 's/.*" "//g'|sed 's/"//g'`
MEAT=`echo $line|cut -d" " -f2-`
echo $SOURCEIP $MEAT >>${LOG}.txt
done<$LOG
can anyone suggest a way of doing this in perl?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.