Reputation: 339
I've got a string that I need to grab two section out - they vary as it's a PHP language file. Hoping someone can help, the string is:
$_LANG['FIELD1'] = "FIELD2";
I need to grab FIELD1 and FIELD2
Upvotes: 0
Views: 136
Reputation: 85913
This should do it:
# space seperated
$ sed -n "s/.*_LANG\['\([^']*\)'] = .\(\w*\).*/\1 \2/p" file
FIELD1 FIELD2
# newline seperated
$ sed -n "s/.*_LANG\['\([^']*\)'] = .\(\w*\).*/\1\n\2/p" file
FIELD1
FIELD2
Or using grep
with positive lookbehind:
$ grep -Po "(?<=_LANG\[')[^']*" file
FIELD1
$ grep -Po '(?<=_LANG\[.FIELD1.\] = ")[^"]*' file
FIELD2
Upvotes: 2