Skip to content
Advertisement

grep to read exact data from text file

I have file test1.txt file, i am trying to read variable which is enclosed in double quotes and starting with hyphen for eg: “-color“. i trying to use this grep command cat test1.txt | grep getParm | sed ‘s/getParm(/ /;s/&/ /;s/,/ /;s/”/ /g’ | awk ‘{print $3}’ , where i am not able to read exact data for all variables present in file. for some of variables which is enclosed in if…else condition i don’t get exact data. Please help me to read the data required. i have posted required data in question.

JavaScript
JavaScript

expected ouput:-

JavaScript

Advertisement

Answer

With GNU grep, positiv lookbehind, a non-greedy * and positiv lookahead:

JavaScript

Output:

-logFile
-color
-species
-width
-length
-LargeTransferLength
-pattern
-volume

See: The Stack Overflow Regular Expressions FAQ

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement