0

I have list of commands where some are having parameters which I need to skip before executing them.

  • show abc(h2) xyz
  • show abc(h2) xyz opq(h1)
  • show abc(h2) xyz <32>
  • show abc(a,l) xyz [<32>] opq
  • show abc

Ultimately, the list has different combinations of ( ), <>, [] with plain text commands. I want to separate out all other commands from plain commands like "show abc".

Processing needed on commands :-

(h1), (h2), (a,l) are to be discarded
<32> - is to be replaced with any ip address
[<32>] - is to be replaced with any integer digit

I tried following but resultant file was empty :-

cat show-cmd.txt | grep "<|(|[" > hard-cmd.txt

How can I get the result file which has no plain commands using regex?

Desired output file :-

show abc xyz
show abc xyz opq
show abc xyz 1.1.1.1
show abc xyz 2 opq
4

2 に答える 2

1

grep続いて使用してみてくださいsed

grep '[(<\[]' file | sed -e 's/\[<32>\]/2/g' -e 's/<32>/1.1.1.1/g' -e 's/([^)]*)//g'

出力:

show abc xyz
show abc xyz opq
show abc xyz 1.1.1.1
show abc xyz 2 opq

s///gあなたの場合、コマンドの順序が重要であることに注意してください。

また、冗長な使用を避けるようにしてくださいcat

于 2013-10-16T06:59:20.690 に答える