-7

So, I have a pretty long text file. I'm trying to update every occurrence of a string of the format 100-AZ-30000 to 200-AZ-40000. I was wondering if I should manually parse every line and search for the substring and update it. I was reading about using regex, but wasn't sure how to begin. Since I'm fairly new, could someone point out to relevant tutorials/directions to accomplish this. I'm comfortable using Java/Python.

lenignes
  • 323
  • 1
  • 5
  • 17
  • Possible duplicate of [java replace specific string in textfile](http://stackoverflow.com/questions/23466179/java-replace-specific-string-in-textfile) – Joseph Young Dec 22 '15 at 20:10
  • @gonzo: OP doesn't show any research effort (you can downvote) but I'm not sure it should be closed using the reason you've provided. *"point out to relevant tutorials/directions"* is not the core of the question: it can be answered as is (see [@Martin's answer](http://stackoverflow.com/a/34423728/4279) -- I don't think it falls into the category of *"opinionated answers or spam"*). ["how do I do X using Y?" questions are pretty useful, even if they don't contain code.](http://meta.stackoverflow.com/questions/274630/should-we-add-a-do-my-work-for-me-close-reason#comment106655_274630) – jfs Dec 22 '15 at 20:24
  • related: [How to search and replace text in a file using Python?](http://stackoverflow.com/q/17140886/4279) – jfs Dec 22 '15 at 20:27
  • Noted. Thanks. @J.F.Sebastian. – gonzo Dec 22 '15 at 20:28

1 Answers1

3

The easiest way to do this if you are running Linux or OS X or Windows/Cygwin is to use sed.

sed -i".bak" -e "s/100-AZ-30000/200-AZ-40000/g" pretty_long_text_file
Martin Konecny
  • 50,691
  • 18
  • 119
  • 145