Issue
I have simple php array in a php file. Here is the content :
<?php
$arr = array(
'fookey' => 'foovalue',
'barkey' => 'barvalue'
);
How can I fetch value foovalue
using grep
command ?
I have tried :
cat file.php | grep 'fookey=>'
Or
cat file.php | grep 'fookey=>*'
but always return the full line.
Solution
Your grep
command shouldn’t have worked if you are doing it just the way you posted it here.
But if you are getting that line from grep
whatever way you are doing,
Pass the output you got from grep
through a pipe to
awk -F"'" '{print $4}'
I tested it this way on my pc:
echo "'fookey' => 'foovalue'" | awk -F"'" '{print $4}'
Answered By - Mihir Luthra