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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献