I have some text as below:
path => ["/home/Desktop/**/auditd.log",
"/home/Desktop/**/rsyslog*.log",
"/home/Desktop/**/snmpd.log",
"/home/Desktop/**/kernel.log",
"/home//Desktop/**/ntpd.log",
"/home/Desktop/**/mysql*.log",
"/home/Desktop/**/sshd.log",
"/hme/Desktop/**/su.log",
"/home/Desktop/**/run-parts(.log"
]
I want to extract the values inside [
]
, so I am doing:
sed -n 's/.*\[\(.*\)\]/\1/p'
Sed is not returning anything.
If I do sed -n 's/.*\[\(.*\)log/\1/p
it's returning properly the string between [
and log
.
"/home/Desktop/**/auditd.",
So it's able to search within the line.
How to make this work??
EDIT:
I created a file with content:
path => [asd,masd,dasd
sdalsd,ad
asdlmas;ldasd
]
When I do grep -o '\[.*\]'
it does not work but grep -o '\[.*'
this returns the 1st line [asd,masd,dasd
. So it's working for single line not for multiple lines.
awk
or some tool that can actually understand the input format. The last bit of this question shows you a very handy awk pattern for range-of-line processing. – Etan Reisnerawk '/\[/,/\]/'
but it's returning an output which is same as input as it's includingpath =>
in the output – Siddharth Trikha