Script to modify contents of txt file

2013-08-12
2014-11-04
  • Rhadamanthys76

    Rhadamanthys76 - 2013-08-12

    Hello everyone

    I am a new user to Notepad++ (literally just installed the program) and would like to know if it supports advanced scripting like modifying data in a txt file

    The problem I have is I need to sort and extract data from text files (reports) that are formatted for legibility rather than being delimited, so the data goes downwards and the strings of information are very variable

    What I'd like to do for example are
    1 - Search for strings "aaa" until the next occurrence of "bbb" and delete the contents
    2 - Search for strings "ccc" until the next occurrence of "ddd" and insert "#" at the start of the line for all those lines of data
    3 - Search for strings "eee" until the next occurrence of "fff" and insert "##" at the start of all those lines of data

    At the end of this I could open the file in excel as delimited by "#" and I`ll have at least the data in a table where I can further extract useful information

    Can somebody please give a pointer as to how I can go about doing this with notepad ++ (which plugins Id need to install etc) I dont have any formal programming skills, but Im very computer savvy and Im an expert with excel. If there are plugins that help accomplish this visually rather than via command line Id prefer that, if not I`ll use whatever other means are available

    Cheers

     
  • Piccolo

    Piccolo - 2014-03-17

    I don't know exactly how to solve your problem but I know if you go to find/replace and select regular expressions you will be able to do what you are planning to do. do a search for regular expressions.

     
  • THEVENOT Guy

    THEVENOT Guy - 2014-11-04

    Hello Rhadamanthys76,

    I'm terribly sorry because I don't regularly look for the Script forum :-(( So, I quite sure that you could manage your problems,from this time, by other means ! Anyway, I give you a very very late answer, just for additional information !

    As Piccolo said in his post, it's easy enough to achieve what you want to, with simple regular expressions :-)

    So :

    • Open the Replace dialog ( CTRL + H )

    • Check the Regular expression search mode ( IMPORTANT )

    • If necessary, uncheck the . matches newline option ( IMPORTANT )

    • If necessary, check the Wrap around option

    However, for your FIRST case, I don't know if you want :

    • To delete all, between the first string aaa and the first string bbb of the line ( Case 1A )

    • To delete all, between the first string aaa and the last string bbb of the line ( Case 1B )

    • To delete all the contents of the line, included the End of Line characters ( Case 1C )

    So :

    • For case 1A => SEARCH aaa.*?bbb and leave the REPLACE zone EMPTY

    • For case 1B => SEARCH aaa.*bbb and leave the REPLACE zone EMPTY

    • For case 1C => SEARCH .*aaa.*bbb.*\R and leave the REPLACE zone EMPTY

    • For case 2 => SEARCH .*ccc.*ddd.* and REPLACE #$0

    • For case 3 => SEARCH .*eee.*fff.* and REPLACE ##$0

    • And, finally, click on the Replace All button

    Et voilà !

    NOTE : The $0 form represents the totality of the searched string

    Best Regards,

    guy038

     
    Last edit: THEVENOT Guy 2014-11-04

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks