Answer the question
In order to leave comments, you need to log in
How to get ip and a specific substring from a string using grep and cut?
From the web server log file, you need to get pairs like IP: __utma. The lines in the file are standard, only through "|" cookies are saved.
80.247.101.110 - - [16/Aug/2013:06:58:23 +0400] "POST /edit HTTP/1.1" 404 327 "http://site.ru/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 YaBrowser/1.7.1364.17262 Safari/537.22" "-" | "__utma=230214667.2058679839.1371519930.1376615440.1376617932.52; __utmc=230214667; __utmz=230214667.1371519930.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
Answer the question
In order to leave comments, you need to log in
Once such a booze has gone, then:
cat test.log | awk '{print $1,":",substr($0, index($0,"__utma"),64)}' | sed 's/ : __utma=/: /' | sed 's/;//'
80.247.101.110: 230214667.2058679839.1371519930.1376615440.1376617932.52
If you can awk, then like this:
cat ./data.txt | awk '{print $1,":",substr($0, index($0,"__utma"),64)}'
Here's how it's possible:
for line in $(cat log);
do
ip=$(echo $line | grep -o "^[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+")
utma=$(echo $line |grep -o "__utma=\([0-9]\+\.\)\+[0-9]\+" | cut -d '=' -f2 )
echo -en "$ip $utma\n"
done
cat log | awk -F"-" '{print $1,$4}' | awk '{print $1":",$4}' | sed 's/"__utma=//g' | sed 's/;$//'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question