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
  • 842
  • 1
  • 8
  • 22

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
  • 451
  • 6
  • 6
1

Simple first attempt:

egrep -o '"([^"]*)"' sourcefile | sed -r 's/"(.*)"/\1/'
Fred Foo
  • 355,277
  • 75
  • 744
  • 836