0

I have 100 notepad files having text like this:

"john is going home
his door number is 0001"

Note: number 0001 or any other number has been applied in all 100 text documents.

In all the remaining files the door number has to be changed to 0002 , 0003, 0004. etc. I don't want to change it by opening each file for 100 times but I need it to be done at once without editing all one by one. In Notepad++ there is replace option but I have no idea of how to work and not pretty sure this can be done. Can this doubt be cleared in Notepad++? or is there any other software available to do this?

  • So text1.txt would have "john is going home his door number is 0001", text2.txt would have "john is going home his door number is 0002", text3.txt would have "john is going home his door number is 0003", and so on ... or they all need to have "john is going home his door number is 0001"? – txtechhelp Dec 18 '16 at 20:12
  • thanks for the reply. your first guess is correct. text2.txt would have "john is going home his door number is 0002", text3.txt would have "john is going home his door number is 0003", and so on. – Abd Dec 19 '16 at 4:18
  • Is it possible with notepad++? or any suggestion? – Abd Dec 19 '16 at 20:42
  • You can use notepad++ to capture and replace values using regular expressions, so you could find and replace all with "john...0001", but I don't know if you can do an incremental replace like you're wanting .. you could do this fairly easy with a VBScript if you're comfortable with scripting though .. – txtechhelp Dec 20 '16 at 3:38
  • thanks. im not good enough skilled in Vbscript but i know a little bit of it. I think i need to do tough research over internet to find out solution for this task. lets see. thanks once again. :) – Abd Dec 20 '16 at 9:01
0

I don't know whether you have access to a Unix environment or Cygwin under Windows, but I think this little bash script that I recycled from an old script I wrote and modified for your example does the work:

#!/bin/bash

for line in {1..100}
    do
        digs=${#line}
        zeros=$((4 - $digs))
        zeros2=$(yes 0 | head -$zeros | paste -s -d '' -)
        numm=$zeros2$line
        printf "john is going home\nhis door number is %s\n" $numm > text$numm.txt
    done
  • thank you Cevikel, this is the method what im exactly looking for but i hv not yet tried it out as im not that familiar to Unix environment and Cygwin, so, first i need to install Cygwin under windows then will go through your workout. Im gonna google how to save this bash script from Cygwin to a file then run it. i hv almost got a help from u. i ll give it a try then let u know. if u can spare some more time pls do let me know how to save this file and run it in win 7. thank u friend – Abd Dec 22 '16 at 21:31
  • I'll try to figure out a way to port this script to Windows Shell. – Serhat Cevikel Dec 22 '16 at 22:25
  • hope you can do it – Abd Dec 24 '16 at 21:35
  • I hv installed Cygwin under windows 7. Can u let me know how to run this bash script? thanks – Abd Dec 26 '16 at 21:37
  • You save the script into a file (preferably with a .sh extension). The first line should be #!/bin/bash if the default shell of your user is bash. You make the script executable with chmod +x /path/to script. Now by typing the path to the script you can execute it. To make the script a command to be executable anywhere, you should put a symlink to one of the paths stated in your $PATH environment variable. Fox example: ln -s /path/to/script /usr/bin/your_command – Serhat Cevikel Dec 28 '16 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.