2

Is there a simple way to extract strings from code i.e. the content of a double quotes?

source:

a = "somestring"

result:

somestring
liborw
  • 832
  • 1
  • 8
  • 21

2 Answers2

1

Fred Foo's answer solves the essential problem. Expanding to report across a directory tree, and to report the file name on each output line even if multiple strings occur on the same line:

find . -name '*.java' | xargs egrep -o '"([^"]*)"' |\
awk '/:"/ {j=$0;sub(/:.*/,"",j);print;}!/:"/{print j ":" $0}' |\
sed 's/"\(.*\)"/\1/'
Jay Dunning
  • 361
  • 4
  • 5
1

Simple first attempt:

egrep -o '"([^"]*)"' sourcefile | sed -r 's/"(.*)"/\1/'
Fred Foo
  • 342,876
  • 71
  • 713
  • 819