I have a big file which is composed of alot of different lines which only have one 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 i need to do is grep for the path that can be found on all storaged keywords that comes after -R. But I only want the path, nothing after that. -R can be found on different places so there is no pattern to it.

I created one espressionen which seemed to work, but I think I made it much for complex (and not 100% sure to match) than it should have to be.

[root:~/scripts/] <conf.txt grep -o 'R  *[^ ]*' | grep -o '[^ ]*$' | sed 's/.*R\///'
/etc/orc/storage123
/etc/orc/storagerabc

The espression also is hard to implement in a bash script so something simpler would be great. I need these paths in the script later on.

Cheers

有帮助吗?

解决方案

Your attempt is nice, but you can simplify it by using a look-behind:

$ grep -Po '(?<=-R )[^ ]*' file
/etc/orc/storage123
/etc/orc/storageabc

Basically it looks for the string -R (note the space) and from that, it prints everything up to a space.

其他提示

$ sed 's/.*-R \([^ ]*\).*/\1/' file
/etc/orc/storage123
/etc/orc/storageabc
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top