dtkf64283 2015-10-21 14:38
浏览 209
已采纳

在Linux上使用sed来格式化字符串

hey guys :) i have a file with a very huge amount of datas ( access logs ) and i have a little problem there.. i want to save all the access logs i have in a database.. and i was able to filter nearly all important data ein need.. besides one and this is my problem... so imagine :

$domain = system(" awk '{print $1}' /var/www/laravel/xxxxxx/xxxxx/xxxxxxx.log");

$1 is the domain - and $2-6 are other datas i need.. but now my problem is that $7 is a important string and i can filter it like i need.. so my first log goes from $7 to $11 - but the seccond log ( from this important string ) goes from $7 to $13 - and now i cant filter them in a right way :/

the only think maybe could help is that this important data is around some ' ( ) '

now i need a command that cuts me every string from the first ( until the last ) - but this important string looks on some logs like this :

( 11111 22222 ) ( 33333 444444)

so i want the whole content from the ' ( ' before 111111 until the ' ) ' after the 4444444

do anyone know how to do this with sed, grep or something else?

  • 写回答

1条回答 默认 最新

  • dpgbh20688 2015-10-21 14:44
    关注

    You probably want to use cut:

    ryan@~:$ cat test
    some text ( 11111 22222 ) ( 33333 444444) some other text
    ryan@~:$ cut -d'(' -f2-3 test | cut -d')' -f1-2
     11111 22222 ) ( 33333 444444
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制