Solved Find and Replace using regular expression

April 1, 2014 at 10:59:14
Specs: windows7, P4 4GB
I have a situation as shown below ..

         1         2
  17001000  10230100  123456
  16001001  10230200  123456
  17001002  10230300  123456

I want to replace 1023 in lines that has 17001 with 1165. Position on the numbers are important. There are two blank spaces in the beginning. that means 1- is in 3rd place,7 is in 4th and so on . So "1023" will be in 13,14,15&16th place.
I am able to find the numbers using regular expression ..17001.....1023 but not able to replace only 1023 to 1165.. I am using 1165 is replace . Am I missing something ??

edited by moderator: Added pre tags and column numbers -Razor2.3

See More: Find and Replace using regular expression

Report •

April 1, 2014 at 11:41:00
rohangraj:Am I missing something ??
Well the language you're using, for one.

I don't like regular expressions when dealing with fixed positions. I find standard string comparisons and text replacements are more predictable and easier to read.

How To Ask Questions The Smart Way

Report •

April 1, 2014 at 14:04:23
✔ Best Answer
Regex support in batch scripting is limited and rudimentary. You should look at using a more robust language.

A very slight adjustment to the perl solution I gave in your prior question would do what you want, but if you have multiple different sets of numbers that you need to match and update, then this solution would need to be adjusted accordingly.

perl -pi.bak -e "s/^\s*(\d\d1456\S+) 2112/$1 1551/" file.txt

Report •

April 1, 2014 at 19:58:29
Mebbe you could post the code you're using thus far. I don't even know which "language" you are using - there are hundreds of possibilities, and there was no feedback from you regarding the solutions offered toward your previous post.

Report •

Related Solutions

April 1, 2014 at 20:07:14
I an using text editors like notepad++ / textpad find & replace regular expression.

Report •

April 1, 2014 at 20:23:51
@nbrane : Sorry for the delay in response. I am still working on previous post.

Report •

Ask Question