替换返回输出中的字符 bash

huangapple go评论51阅读模式
英文:

Replacing chars in returned output bash

问题

I can help you with the translation:

我可以帮助您进行翻译:

im tryng to run this command to grep the exploit MS-* from metasploit exploit's dir

我尝试运行此命令来从metasploit exploit目录中查找MS-*的漏洞

locate -r ".rb$" | xargs grep "MSB" | grep metasploit | grep exploit | grep smb | awk '{print $3,$4}'

找到 -r ".rb$" | xargs grep "MSB" | grep metasploit | grep exploit | grep smb | awk '{print $3,$4}'

i got this result :

我得到了这个结果:

> grep: /usr/share/doc/ruby-http-parser.rb: Is a directory

> grep:/usr/share/doc/ruby-http-parser.rb:是一个目录

> 'MS17-010'],

> 'MS17-010'],

> 'MSB', 'MS03-049'

> 'MSB', 'MS03-049'

> 'MSB', 'MS04-007'],

> 'MSB', 'MS04-007'],

> 'MSB', 'MS04-011'

> 'MSB', 'MS04-011'

> 'MSB', 'MS04-031'],

> 'MSB', 'MS04-031'],

> 'MSB', 'MS05-039'

> 'MSB', 'MS05-039'

> 'MSB', 'MS06-025'

> 'MSB', 'MS06-025'

> 'MSB', 'MS06-040'

> 'MSB', 'MS06-040'],

> 'MSB', 'MS06-066'],

> 'MSB', 'MS06-066'],

> 'MSB', 'MS06-070'

> 'MSB', 'MS06-070'],

> 'MS07-029']

> 'MS07-029']

> MS08-067),

> MS08-067),

> 'MSB', 'MS09-050'

> 'MSB', 'MS09-050'

how i can remove this ('MSB', ' ) and ('])from each line

如何删除每行中的('MSB',')和('])?

i need output like this :

我需要类似这样的输出:

> MS09-050

> MS09-050

> MS08-067

> MS08-067

> MS06-070

> MS06-070

and also i need to remove the first line ( grep: /usr/share/doc/ruby-http-parser.rb: Is a directory )

我还需要删除第一行(grep:/usr/share/doc/ruby-http-parser.rb:是一个目录)

英文:

im tryng to run this command to grep the exploit MS-* from metasploit exploit's dir

locate -r "\.rb$" | xargs grep "MSB" | grep metasploit | grep exploit | grep smb | awk '{print $3,$4}'

i got this result :

> grep: /usr/share/doc/ruby-http-parser.rb: Is a directory
>
> 'MS17-010'],
>
> 'MSB', 'MS03-049'
>
> 'MSB', 'MS04-007'],
>
> 'MSB', 'MS04-011'
>
> 'MSB', 'MS04-031'],
>
> 'MSB', 'MS05-039'
>
> 'MSB', 'MS06-025'
>
> 'MSB', 'MS06-025'
>
> 'MSB', 'MS06-040'
>
> 'MSB', 'MS06-066'],
>
> 'MSB', 'MS06-066'],
>
> 'MSB', 'MS06-070'
>
> 'MS07-029']
>
> MS08-067),
>
> 'MSB', 'MS09-050'

how i can remove this ('MSB', ' ) and ('])from each line

i need output like this :

> MS09-050
>
> MS08-067
>
> MS06-070
>
> ..
>
> ..
>
> ..

and also i need to remove the first line ( grep: /usr/share/doc/ruby-http-parser.rb: Is a directory )

答案1

得分: 0

locate -r "\.rb$" | xargs grep -s "MSB" | grep metasploit | grep exploit | grep smb | awk '{print $3,$4}' | sed "s/[,' )]//g" | sed "s/MSB //g" | sed "s/]//g"
英文:
locate -r "\.rb$" | xargs grep -s "MSB" | grep metasploit | grep exploit | grep smb | awk '{print $3,$4}'|sed "s/[,')]//g" |sed "s/MSB //g"|sed "s/]//g"

Explanation:

  • sed "s/[,')]//g" - removes , ' and ) from each line.

  • sed "s/MSB //g"|sed "s/]//g" - removes MSB from each line.

  • sed "s/]//g" - removes ]

  • xargs grep -s "MSB" - the -s option in grep will suppress error messages for that output.

huangapple
  • 本文由 发表于 2020年1月6日 16:52:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609115.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定