linux - how to get the text in shell between two specific character ( [ ] bracket ) with sed? -


i try text in shell between 2 specific character sed, in shell, doesnt seem work.

i try text "[" , "]"

[561:0:43:0] ->  561:0:43:0  

so tried follow

sed -e '/[/,/]/p' test > test2 

test content example:

[561:0:42:0] [561:0:43:0]  [561:0:478:0] [561:0:48:0]  [562:0:9:0]   

after command when read test2 still contains brackets

i tried search alternatives here, cant find anĂ­thing work.

any suggestion ? thanks

you didnt expected output becuase

  • p command prints entire pattern space,( or in sed command current line read)

you can use like

$ sed -r 's/\[(.*)\]/\1/g' test 561:0:42:0 561:0:43:0 561:0:478:0 561:0:48:0 562:0:9:0  
  • s commands substitutes within [] contents of \1 capture group 1, caputured (.*)

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -