grep and/or sed to match a path from a string which has different patterns -
i have big file composed of alot of different lines have 1 commen keyword, storaged.
proc:storage123:0702:2108:0,1,2,3,4,5:storage:vers:storaged:storage123:storage 123:storage123:-r /etc/orc/storage123 -e emr123@localhost -p xxx:: proc:storageabc:0606:2108:0,1,2,3,4,5:storage:vers:storaged:storageabc:storage abc:storageabc: -e emabc@localhost -r /etc/orc/storageabc -p 654::
what need grep path can found on storaged keywords comes after -r. want path, nothing after that. -r can found on different places there no pattern it.
i created 1 espressionen seemed work, think made complex (and not 100% sure match) should have be.
[root:~/scripts/] <conf.txt grep -o 'r *[^ ]*' | grep -o '[^ ]*$' | sed 's/.*r\///' /etc/orc/storage123 /etc/orc/storagerabc
the espression hard implement in bash script simpler great. need these paths in script later on.
cheers
your attempt nice, can simplify using look-behind:
$ grep -po '(?<=-r )[^ ]*' file /etc/orc/storage123 /etc/orc/storageabc
basically looks string -r
(note space) , that, prints space.
Comments
Post a Comment