我的日志文件包含一些数据,如下所示
2016-01-21 16:18:23,644 SECURE POST Data (accounts.google.com):
Page=SignIn&GALX=lw6hYFRj2vg&gxf=AFoagUWl6uaAvm41g5BiLg4tzAG3rzr4Bw%3A1453389448463&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F&service=mail&rm=false<mpl=default&scc=1&ss=1&osid=1&_utf8=%E2%98%83&bgresponse=%21e3hCAbRRQ3hYrxREZng_0CIqYqYCAAAHwVIAAAAPCgAul8aVFVW6vFlJlCUbkcM-dCTX3viATy-tutZZ_Ly-Y5YBPm6Yuj40a_bnqPMlDyoA9UmspmGcwKh4Noz6dvw89DccGJhC0OlSmloJ5VdtG0XAxn35sIzwmEMIgVu2_4O_EstPMi7vmIJCqhPE3h5yCgAQ2KWuWil0RkW9M35uq-7KCq3dOsbPdONTRzD0nhhxKTj2SS5nuHTDxcMqZNyKs-YnNgKJwTqaooxfPHmzbMl2QC9Sn7cGBVmjWjJgpZpLXNKKjXLUYswDkjcI2dIR1-u7nNIapY4f2btHyoQi3DweV12Xck9dPgDNepXpsv9rqgbLzogYKevZtgNvYJnB5TyYl8vLf1zAdQ7gs-bjc4tJ7k-s7CUp6GY8tSk8b9ylmEs99ekZ&pstMsg=1&dnConn=&checkConnection=&checkedDomains=youtube&Email=adressmail@gmail.com&Passwd=somehardpass&signIn=Sign+in&PersistentCookie=yes&rmShown=1
2016-01-21 16:21:23,767 POST Data (store.steampowered.com):
donotcache=1453422082051&username=steamusser
2016-01-21 16:22:17,378 SECURE POST Data (login.live.com):
loginfmt=mailhotmail@hotmail.com&passwd=password&login=mailhotmail@hotmail.com&type=11&PPFT=DQ*u1t4V8*JGcTxFANAPwd1ir7J4MwRwvmveEIfUgySN%211dU2tRMIAUjqfG1ZAuzBE2FZlf7kF8%21UFfCIoI0ohkICsbu02bh88rUKcLnLbSfJC%21NzmGFT5OdXr*xoxhRZndArR*PiGXEtlofqMnNEyWBzJ25iXmQPXLG1htBags20SfL6WoNd2OVduOfYehkTDcIOUEs37BdW8OXtVJiIDxcn3DgSZQuzccPLRwStOiq&PPSX=P&idsbho=1&sso=0&NewUser=1&LoginOptions=3&i1=0&i2=1&i3=87238&i4=0&i7=0&i12=1&i13=0&i14=531&i15=1775&i17=0&i18=__Login_Strings%7C1%2C__Login_Core%7C1%2C
我使用grep命令获取网站
grep -oP '\(\K[^)]*' log.txt
它告诉我
accounts.google.com
store.steampowered.com
login.live.com
使用
获取登录名/用户名 grep -oP 'login\K[^&]*' log.txt
grep -oP 'user=\K[^&]*' log.txt
grep -oP 'username=\K[^&]*' log.txt
grep -oP 'EMAIL=\K[^&]*' log.txt
它显示了我的用户名,登录信息,电子邮件
Email=adressemail@gmail.com
username=steamusser
etc.
我想做的是回归
accounts.google.com
Email=adressemail@gmail.com
store.steampowered.com
username=steamusser
如何在一行中执行所有这些grep命令。我已尝试用|操作OR操作但它不会为我工作。我是bash和grep的新手。你们能帮助我吗?
答案 0 :(得分:2)
一起制作你的正则表达式:
kent$ grep -oP '\(\K[^)]*|(user|username|Email|login)=[^&]*' file
accounts.google.com
Email=adressmail@gmail.com
store.steampowered.com
username=steamusser
login.live.com
login=mailhotmail@hotmail.com