-1

I need some help with the perl script. I basically want to read each line a file (each line will have one word enclosed within double quotes) and replace that word.

For example:

here are the content of the file:

"word 1" some string contents
"word 2" some string contents
"word 3" some string contents.

how to replace word 1, word 2, and word 3 in each line..?

Any help will be greatly appreciated!

thanks,

Miller
  • 34,962
  • 4
  • 39
  • 60
user2812535
  • 13
  • 2
  • 9
  • Can you have escaped quotes inside your quotes? If not, then it's as simple as `s/"[^"]*"/replace me/` – knittl Mar 31 '14 at 13:46
  • And if not, it's simple as well: `s/"(?:\\.|[^"])*"//g` But this question is quite unclear: what should be the replacement, should only the first such word in each line be replaced etc. – raina77ow Mar 31 '14 at 13:46
  • 7 hours ago someone asked a similar question. http://stackoverflow.com/questions/22754913/perl-regex-to-match-string-syntax – clt60 Mar 31 '14 at 13:51

1 Answers1

0

You can use a one-liner for this:

perl -pi -e 's/^"[^"]*"/<replacement>/g' <filename>

it isn't really clear from your question what are you replacing with, so just fill in the blanks.

Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170