dtkf64283
2015-10-21 14:38 阅读 156
已采纳

在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 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
    
    点赞 评论 复制链接分享

相关推荐